This document describes how I set up my developer environment on a new MacBook or iMac. We will set up Java, Node (JavaScript), Python, and Ruby environments, mainly for JavaScript and Python] development. Even if you don't program in all, it is good to have them as many command-line tools use one of them. As you read and follow these steps, feel free to send me any feedback or comments you may have.
The document assumes you are new to Mac. The steps below were tested on OS X Yousemite.
If you have any comments or suggestions, feel free to give me a shout on Weibo!
- System Update
- System Preferences
- Google Chrome
- JDK
- iTerm2
- Homebrew
- Git
- Maven
- Tomcat
- IntelliJ Idea
- Beautiful Terminal
- iTerm2
- Sublime Text
- MySQL
- MySQL Workbench
- Sequel Pro
- Projects Folder
First thing you need to do, on any OS actually, is update the system! For that: Apple Icon > Software Update...
If this is a new computer, there are a couple tweaks I like to make to the System Preferences. Feel free to follow these, or to ignore them, depending on your personal preferences.
In Apple Icon > System Preferences:
- Trackpad > Tap to click
- Keyboard > Key Repeat > Fast (all the way to the right)
- Keyboard > Delay Until Repeat > Short (all the way to the right)
- Dock > Automatically hide and show the Dock
- Accessibility > Trackpad Options > Enable dragging (three finger drag)
Install your favorite browser, mine happens to be Chrome.
Download from www.google.com/chrome. Open the .dmg file once it's done downloading (this will mount the disk image), and drag and drop the Google Chrome app into the Applications folder (on the Mac, most applications are installed this way). When done, you can unmount the disk in Finder (the small "eject" icon next to the disk under Devices).
Type javac in termial, go on with the detail information button. It will lead you to Oracle's download page. Select a suitable version, download the dmg file and go on with the installation.
Set up $JAVA_HOME parameter for terminal. Open .bash_profile and add the following.
# suppose v1.6 is used.
export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)Since we're going to be spending a lot of time in the command-line, let's install a better terminal than the default one. Download and install iTerm2 (the newest version, even if it says "beta release").
In Finder, drag and drop the iTerm Application file into the Applications folder.
You can now launch iTerm, through the Launchpad for instance.
Let's just quickly change some preferences. In iTerm > Preferences..., under the tab General, uncheck Confirm closing multiple sessions and Confirm "Quit iTerm2 (Cmd+Q)" command under the section Closing.
In the tab Profiles, create a new one with the "+" icon, and rename it to your first name for example. Then, select Other Actions... > Set as Default. Finally, under the section Window, change the size to something better, like Columns: 125 and Rows: 35.
When done, hit the red "X" in the upper left (saving is automatic in OS X preference panes). Close the window and open a new one to see the size change.
Package managers make it so much easier to install and update applications (for Operating Systems) or libraries (for programming languages). The most popular one for OS X is Homebrew.
An important dependency before Homebrew can work is the Command Line Tools for Xcode. These include compilers that will allow you to build things from source.
Now, Xcode weights something like 2GB, and you don't need it unless you're developing iPhone or Mac apps. Good news is Apple provides a way to install only the Command Line Tools, without Xcode. To do this you need to go to http://developer.apple.com/downloads, and sign in with your Apple ID (the same one you use for iTunes and app purchases). Unfortunately, you're greeted by a rather annoying questionnaire. All questions are required, so feel free to answer at random.
Once you reach the downloads page, search for "command line tools", and download the latest Command Line Tools (OS X 10.10) for Xcode. Open the .dmg file once it's done downloading, and double-click on the .pkg installer to launch the installation. When it's done, you can unmount the disk in Finder.
Note: If you are running OS X 10.9 Mavericks, then you can install the Xcode Command Line Tools directly from the command line with $ xcode-select --install, and you don't have to go through the download page and the questionnaire.
Finally, we can install Hombrew! In the terminal paste the following line (without the $), hit Enter, and follow the steps on the screen:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
One thing we need to do is tell the system to use programs installed by Hombrew (in /usr/local/bin) rather than the OS default if it exists. We do this by adding /usr/local/bin to your $PATH environment variable:
$ echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
Open a new terminal tab with Cmd+T (you should also close the old one), then run the following command to make sure everything works:
$ brew doctor
Change setting to use chinese mirror. Thanks ban.nijia
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=http://7xkcej.dl1.z0.glb.clouddn.com' > ~/.bash_profile # or .bashrc
$ cd /usr/local
$ git remote set-url origin https://gitcafe.com/ban-ninja/homebrew.git
To install a package (or Formula in Homebrew vocabulary) simply type:
$ brew install <formula>
To update Homebrew's directory of formulae, run:
$ brew update
Note: I've seen that command fail sometimes because of a bug. If that ever happens, run the following (when you have Git installed):
$ cd /usr/local
$ git fetch origin
$ git reset --hard origin/master
To see if any of your packages need to be updated:
$ brew outdated
To update a package:
$ brew upgrade <formula>
Homebrew keeps older versions of packages installed, in case you want to roll back. That rarely is necessary, so you can do some cleanup to get rid of those old versions:
$ brew cleanup
To see what you have installed (with their version numbers):
$ brew list --versions
I really like the Consolas font for coding. Being a Microsoft (!) font, it is not installed by default. Since we're going to be looking at a lot of terminal output and code, let's install it now.
There are two ways we can install it. If you bought Microsoft Office for Mac, install that and Consolas will be installed as well.
If you don't have Office, follow these steps:
$ brew install cabextract
$ cd ~/Downloads
$ mkdir consolas
$ cd consolas
$ curl -O http://download.microsoft.com/download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26/PowerPointViewer.exe
$ cabextract PowerPointViewer.exe
$ cabextract ppviewer.cab
$ open CONSOLA*.TTF
And click Install Font. Thanks to Alexander Zhuravlev for his post.
Since we spend so much time in the terminal, we should try to make it a more pleasant and colorful place. What follows might seem like a lot of work, but trust me, it'll make the development experience so much better.
Let's go ahead and start by changing the font. In iTerm > Preferences..., under the tab Profiles, section Text, change both fonts to Consolas 13pt.
Now let's add some color. I'm a big fan of the Solarized color scheme. It is supposed to be scientifically optimal for the eyes. I just find it pretty.
Scroll down the page and download the latest version. Unzip the archive. In it you will find the iterm2-colors-solarized folder with a README.md file, but I will just walk you through it here:
- In iTerm2 Preferences, under Profiles and Colors, go to Load Presets... > Import..., find and open the two .itermcolors files we downloaded.
- Go back to Load Presets... and select Solarized Dark to activate it. Voila!
Note: You don't have to do this, but there is one color in the Solarized Dark preset I don't agree with, which is Bright Black. You'll notice it's too close to Black. So I change it to be the same as Bright Yellow, i.e. R 83 G 104 B 112.
Not a lot of colors yet. We need to tweak a little bit our Unix user's profile for that. This is done (on OS X and Linux), in the ~/.bash_profile text file (~ stands for the user's home directory).
We'll come back to the details of that later, but for now, just download the files .bash_profile, .bash_prompt, .aliases attached to this document into your home directory (.bash_profile is the one that gets loaded, I've set it up to call the others):
$ cd ~
$ curl -O https://raw.githubusercontent.com/awayings/mac-dev-setup/master/.bash_profile
$ curl -O https://raw.githubusercontent.com/awayings/mac-dev-setup/master/.bash_prompt
$ curl -O https://raw.githubusercontent.com/awayings/mac-dev-setup/master/.aliases
With that, open a new terminal tab (Cmd+T) and see the change! Try the list commands: ls, ls -lh (aliased to ll), ls -lha (aliased to la).
At this point you can also change your computer's name, which shows up in this terminal prompt. If you want to do so, go to System Preferences > Sharing. For example, I changed mine from "Nicolas's MacBook Air" to just "MacBook Air", so it shows up as MacBook-Air in the terminal.
Now we have a terminal we can work with!
(Thanks to Mathias Bynens for his awesome dotfiles.)
What's a developer without Git? To install, simply run:
$ brew install git
When done, to test that it installed fine you can run:
$ git --version
And $ which git should output /usr/local/bin/git.
Let's set up some basic configuration. Download the .gitconfig file to your home directory:
$ cd ~
$ curl -O https://raw.githubusercontent.com/awayings/mac-dev-setup/master/.gitconfig
It will add some color to the status, branch, and diff Git commands, as well as a couple aliases. Feel free to take a look at the contents of the file, and add to it to your liking.
Next, we'll define your Git user (should be the same name and email you use for GitHub and Heroku):
$ git config --global user.name "Your Name Here"
$ git config --global user.email "your_email@youremail.com"
They will get added to your .gitconfig file.
To push code to your GitHub repositories, we're going to use the recommended HTTPS method (versus SSH). So you don't have to type your username and password everytime, let's enable Git password caching as described here:
$ git config --global credential.helper osxkeychain
Note: On a Mac, it is important to remember to add .DS_Store (a hidden OS X system file that's put in folders) to your .gitignore files. You can take a look at this repository's .gitignore file for inspiration.
SSH key allows you to establish a secure connection between your computer and GitLab
To generate a new SSH key just open your terminal and use code below.
ssh-keygen -t rsa -C "jing.zhang.sh2@dianping.com"# Creates a new ssh key using the provided email
# Generating public/private rsa key pair...
Next just use code below to dump your public key and add to GitLab SSH Keys
cat ~/.ssh/id_rsa.pub
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....
Reference to: SSH-HELP
With the terminal, the text editor is a developer's most important tool. Everyone has their preferences, but unless you're a hardcore Vim user, a lot of people are going to tell you that Sublime Text is currently the best one out there.
Go ahead and download it. Open the .dmg file, drag-and-drop in the Applications folder, you know the drill now. Launch the application.
Note: At this point I'm going to create a shortcut on the OS X Dock for both for Sublime Text and iTerm. To do so, right-click on the running application and select Options > Keep in Dock.
Sublime Text is not free, but I think it has an unlimited "evaluation period". Anyhow, we're going to be using it so much that even the seemingly expensive $70 price tag is worth every penny. If you can afford it, I suggest you support this awesome tool. :)
Just like the terminal, let's configure our editor a little. Go to Sublime Text 2 > Preferences > Settings - User and paste the following in the file that just opened:
{
"font_face": "Consolas",
"font_size": 13,
"rulers":
[
79
],
"highlight_line": true,
"bold_folder_labels": true,
"highlight_modified_tabs": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"word_wrap": false,
"indent_to_bracket": true
}Feel free to tweak these to your preference. When done, save the file and close it.
I use tab size 2 for everything except Python and Markdown files, where I use tab size 4. If you have a Python and Markdown file handy (or create dummy ones with $ touch dummy.py), for each one, open it and go to Sublime Text 2 > Preferences > Settings - More > Syntax Specific - User to paste in:
{
"tab_size": 4
}Now for the color. I'm going to change two things: the Theme (which is how the tabs, the file explorer on the left, etc. look) and the Color Scheme (the colors of the code). Again, feel free to pick different ones, or stick with the default.
A popular Theme is the Soda Theme. To install it, run:
$ cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/
$ git clone https://github.com/buymeasoda/soda-theme/ "Theme - Soda"
Then go to Sublime Text 2 > Preferences > Settings - User and add the following two lines:
"theme": "Soda Dark.sublime-theme",
"soda_classic_tabs": true
Restart Sublime Text for all changes to take effect (Note: on the Mac, closing all windows doesn't close the application, you need to hit Cmd+Q).
The Soda Theme page also offers some extra color schemes you can download and try. But to be consistent with my terminal, I like to use the Solarized Color Scheme, which already ships with Sublime Text. To use it, just go to Sublime Text 2 > Preferences > Color Scheme > Solarized (Dark). Again, this is really according to personal flavors, so pick what you want.
Sublime Text 2 already supports syntax highlighting for a lot of languages. I'm going to install a couple that are missing:
$ cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/
$ git clone https://github.com/jashkenas/coffee-script-tmbundle CoffeeScript
$ git clone https://github.com/miksago/jade-tmbundle Jade
$ git clone https://github.com/danro/LESS-sublime.git LESS
$ git clone -b SublimeText2 https://github.com/kuroir/SCSS.tmbundle.git SCSS
$ git clone https://github.com/nrw/sublime-text-handlebars Handlebars
Let's create a shortcut so we can launch Sublime Text from the command-line:
$ cd ~
$ mkdir bin
$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Now I can open a file with $ subl myfile.py or start a new project in the current directory with $ subl .. Pretty cool.
Sublime Text is very extensible. For now we'll leave it like that, we already have a solid installation. To add more in the future, a good place to start would be to install the Sublime Package Control.
Select a suitable version maven according to your Java version. In dianping we use JDK 1.6(?), Maven 3.0.5 is OK.
$ brew install maven30
If install sucessfully, we could get the installation path for maven. Export $M2_HOME for environment
$ echo 'export M2_HOME=/usr/local/Cellar/maven30/3.0.5/libexec' >> .bash_profile
Copy .m2 directory to ~/.m2 from your mentor for repository setting and downloaed cache.
Select a suitable version tomcat according to you JA
Download IntelliJ Idea from its main page.
Choose import file from CVS
Maven clean and install
Click + in Preference -> Application Server setting panel, and add local server for tomcat
Click Run -> Edit configurations..., add artifacts for deploys.
We will install MySQL using Homebrew, which will also install some header files needed for MySQL bindings in different programming languages (MySQL-Python for one).
To install, run:
$ brew update # Always good to do
$ brew install mysql
As you can see in the ouput from Homebrew, before we can use MySQL we first need to set it up with:
$ unset TMPDIR
$ mkdir /usr/local/var
$ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
To start the MySQL server, use the mysql.server tool:
$ mysql.server start
To stop it when you are done, run:
$ mysql.server stop
You can see the different commands available for mysql.server with:
$ mysql.server --help
To connect with the command-line client, run:
$ mysql -uroot
(Use exit to quit the MySQL shell.)
Note: By default, the MySQL user root has no password. It doesn't really matter for a local development database. If you wish to change it though, you can use $ mysqladmin -u root password 'new-password'.
In terms of a GUI client for MySQL, I'm used to the official and free MySQL Workbench. But feel free to use whichever you prefer.
You can find the MySQL Workbench download here. (Note: It will ask you to sign in, you don't need to, just click on "No thanks, just start my download!" at the bottom.)
Another small but powerfull sql command. You could easily export selected data as json format. Download link [here|http://www.sequelpro.com/download]
This really depends on how you want to organize your files, but I like to put all my version-controlled projects in ~/projects. Other documents I may have, or things not yet under version control ~/Documents
~/projects~/documents/usr/localPlace for third-party software/usr/local/CellarBrew's default target installation place./Library/Java/JavaVirtualMachines/Oracle's java virtual machine installaiton place./System/Library/Frameworks/JavaVM.frameworkMac's own installation of java