This document describes the process of configuring a new Mac OS-X development environment from scratch.
Last updated: February 2018.
In System Preferences > Users and Groups
, create a new admin user. Restart your computer and login as the new user. Delete the old user and any corresponding home folders.
In System Preferences > Security and Privacy > FileVault
, turn FileVault ON. Take a screenshot of the recovery code. Restart the computer when prompted. Monitor progress for the next 20 minutes.
In System Preferences > Keyboard
:
In System Preferences > Mission Control
:
Open the Mission Control application and create four new linear horizontal Spaces.
Turn Dock hiding on, maximize the size of the Dock, and remove all unnecessary programs from the Dock.
The terminal application is a developer’s main tool.
Download the Solarized color themes, and unzip.
In Terminal Settings, import a new Profile, and choose the solaraized/osx-terminal.app-colors-solarized/Solarized Dark ansi.terminal theme.
Set the Solarized Dark profile theme as default.
Increase font size to 18.
Restore ~/.bash_profile:
# ~/.bash_profile
#
# CONFIGURATION
#
export PS1=" --->> "
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
#
# SHORTCUTS
#
alias ll="ls -lahG"
alias gb="git branch"
alias gd="git diff"
alias gl="git log"
alias glt="git log --graph --decorate --oneline --full-history --all --simplify-by-decoration"
alias glsd="git ls-files --deleted"
alias gpom="git pull origin master"
alias gr="git remote -v"
alias gs="git status"
Review startup agents, and remove as necessary:
launchctl list | grep -v -e 'com.apple' # list
launchctl remove com.xyz.123.def # remove
SSH keys establish your identity, and are a prerequisite for using git and connecting via ssh to known servers.
Generate new ssh keys.
ssh-keygen -t rsa -b 4096 -C johndoe@example.com # generate new key pair
eval "$(ssh-agent -s)" # start the ssh-agent in the background
ssh-add ~/.ssh/id_rsa # add to keychain
If running OS Sierra 10.12.2 or later, create/update ~/.ssh/config
to automatically load keys into the ssh-agent and store passphrases in your keychain:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Finally, copy the public key and add to GitHub and other hosts, as necessary.
pbcopy < ~/.ssh/id_rsa.pub # copy to clipboard
Xcode is a prerequisite for the homebrew package manager.
Create a new Apple ID, and verify your email.
Download Xcode. It might take 30 minutes. View progress from the Launchpad app.
Some homebrew formulae like git
and ruby-build
might need xcode command line tools, so install those now:
xcode-select --install
Homebrew is a package manager for mac os which is used to install applications, programming languages, command-line tools, etc.. It’s trusted and maintained by a large community of developers.
Install the Homebrew package manager:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Turn off brew analytics:
brew analytics off
Install Homebrew Cask for downloading native applications.
brew tap caskroom/cask
Install and/or open Google Chrome, and set it as the default browser.
brew cask install google-chrome
Open chrome and sign-in as an existing chrome user.
Install or re-configure Ghostery to block browser activity trackers.
Install the Atom text editor.
brew cask install atom
Install sync-settings.
apm install sync-settings
Find an existing github personal access token, or generate a new token. It should have permission to create gists.
Find the id of an existing github gist which contains previous atom sync settings, or create a new gist.
In atom’s package settings, input your github access token and gist id. If you have trouble finding the package settings, try opening a new atom window to reveal a warning message and link to the package settings.
Finally, click “restore” to restore text editor settings. The next time you open a new atom window, you should see a sync success message.
Install Git.
brew install git
Configure Git credentials:
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git config --global core.editor atom
Use an email address which has been linked to your GitHub profile and verified.
Configure rubygems.org credentials:
mkdir ~/.gem
curl -u MY_RUBYGEMS_USERNAME https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials
Type your rubygems.org password when prompted.
Many of the following sections are optional, depending on what type of development environment you need.
As a developer working on more than one ruby project, it sometimes becomes necessary to specify different ruby versions for each project. Rbenv makes switching ruby versions easy. Ruby-build, a component of rbenv, facilitates installation of ruby versions.
brew install rbenv
rbenv init # and follow the instructions to add to ~/.bash_profile: eval "$(rbenv init -)"
Restart your terminal for the profile changes to take place.
Use rbenv to install a ruby version and set your computer to use it:
rbenv install 2.3.5 # to install a specific ruby version from the internet
rbenv global 2.3.5 # to set a specific ruby version for use
If you run into trouble, make sure you have installed xcode command line tools and these core libraries: brew install openssl libyaml libffi
.
Install global gems, including the bundler package manager:
gem install bundler
Install ruby on rails:
gem install rails
Install python (includes the pip package manager):
brew install python3
pip3 install django
pip3 install flask
Check if NVM is installed:
command -v nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
This also installs the node package manager (npm).
Use NVM to check for available Node.js versions, install a specific version:
nvm ls-remote # checks for available versions
nvm install 8.9.3 # installs a specific version, and automatically starts using it
Install the express application generator:
npm install express-generator -g
npm install react-native-cli -g
see also: react-native android development environment setup guide
cd my_app/
npm install -g bower
# /usr/local/bin/bower -> /usr/local/lib/node_modules/bower/bin/bower
# bower@1.4.1 /usr/local/lib/node_modules/bower
Install.
brew install postgresql
brew services start postgresql
createdb # to create a database named after your root database user, which is named after your mac username; avoids `psql: FATAL: database my_db_user does not exist`
If desired, set a password for the database root user.
psql -U my_db_user -c "ALTER USER my_db_user WITH PASSWORD 'CHANGE_ME';"
If you want to require password authentication, find the location of the pg_hba.conf file using psql -U my_db_user -c "SHOW hba_file;"
, and edit it to resemble to the following template:
# TYPE DATABASE USER ADDRESS METHOD
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
Basically you are just changing the methods from trust
to md5
. Restart the server to apply the authentication changes.
brew services restart postgresql
psql -U my_db_user # you should now be prompted for a password
Helpful psql commands and their SQL equivalents:
SELECT * FROM pg_user;
-- or... `\du`
SELECT * FROM pg_database;
-- or... `\l`
SELECT * FROM pg_table WHERE schema_name = 'my_db';
-- or... `\connect my_db` and `\dt`
Optionally install the pg gem/driver if you are going to be connecting with a Ruby on Rails app. Find the pg_config file with psql -U my_db_user -c "SHOW config_file;"
.
gem install pg
# if there is an error and you need to specify the config file: gem install pg -- --with-pg-config=/usr/local/bin/pg_config
Optionally create an application database and database user.
CREATE USER app_user WITH password 'CHANGE_ME';
ALTER USER app_user CREATEDB;
ALTER USER app_user WITH SUPERUSER;
CREATE DATABASE app_db;
GRANT ALL PRIVILEGES ON DATABASE app_db to app_user;
Finally, install pgAdmin or pSequel or Postico database management software. Specify your root database user credentials when connecting to the local database server.
brew cask install postico # or... brew cask install psequel
Install MySQL:
brew install mysql
brew services start mysql
mysql -uroot # log-in as the root user
If desired and necessary, secure the connection:
DELETE FROM mysql.user WHERE host <> 'localhost' OR USER = "";
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('cleartext password');
Helpful mysql commands:
SELECT * FROM mysql.user;
SELECT distinct table_schema FROM information_schema.tables; -- or `SHOW DATABASES;`
SELECT * FROM information_schema.tables;
SELECT * FROM information_schema.tables WHERE table_schema = 'my_db';
Finally, install Sequel Pro database management software. Specify your root database user credentials when connecting to the local database server.
brew cask install sequel-pro
Install mongoDB.
brew install mongodb
Follow post-installation instructions.
brew services start mongodb
FYI - the mongo config file specifies the expected paths to the mongo data directory and logfile.
cat /usr/local/etc/mongod.conf
Check your version.
mongo --version
MongoDB shell version: 3.2.9
Run mongo.
mongo
Helpful mongo shell commands:
db # to show the active database
show dbs # to show all databases (this doesn't work?)
use myNewDatabase # create/use a new database
show collections # list all collections in the current database (alternate)
db.getCollectionNames() # list all collections in the current database
db.myCollection.insert( { x: 1 } ); # insert a new record
db.myCollection.insert( { y: 2 } );
db.myCollection.find().pretty() # print collection
db.myCollection.find({x:1}).pretty() # find a record matching given query conditions
Install redis.
brew install redis
brew services start redis
Login to redis:
redis-server
Install elasticsearch.
brew install elasticsearch
NOTE: If you get the error Java 1.7+ is required to install this formula., run:
brew tap caskroom/versions
andbrew cask install java7
and optionally manage java versions with jenv.
Run elasticsearch.
elasticsearch
Install phantomjs (http://phantomjs.org/):
brew install phantomjs
If using the rails-erd
gem, satisfy ruby-graphviz
dependency by installing the graphviz
library.
brew install graphviz
Download heroku toolbelt to enable heroku
command line tools.
brew install heroku-toolbelt
heroku login