Frontend Development Setup on a Mac
TODO -
- Update to Yosemite
- homebrew cask
- add developer tools experiment flags on chrome chrome://flags
- look over rbenv https://github.com/sstephenson/rbenv
- enable blackboxing [ manage framework blackboxing on chrome]
- Allow apps downloaded from anywhere system preferences
- brew install zsh
- change NVM to wget https://github.com/creationix/nvm
This document assumes you're running a fresh copy of OS X Mavericks.
If you have any comments or suggestions, feel free to give me a shout on Twitter!
- System update
- Reset Modifier Keys
- Homebrew
- Homebrew Cask
- Maximum Awesome
- Google Chrome
- Google Chrome Canary
- Firefox
- Slate
- VirtualBox
- Sublime Text
- Ruby & Rbenv
- Git
- Sublime Text
- Vim
- Node.js
- Yeoman
- Bower
- Grunt
- Heroku
- MongoDB
- Projects folder
- Apps
System update
First thing you need to do, on any OS actually, is update the system! For that: Apple Icon > Software Update
Reset Modifier Keys
Replace your Control Key with the Caps lock key. Caps lock is useless. It's a huge icon, easy for your pinky to hit and it'll make life easier when working with vim. System Preferences > Search for Reset Modifier Keys
Projects Directory
Create a project directory somewhere on your machine. I like to use ~/Sites and I'll split that into work/personal/temp. If you fire up terminal (Command + Spacebar -> Type: Terminal -> Enter) you will be able to run this command to automatically create those directories for you:
$ mkdir -p ~/Sites/{personal,tmp,work}
Homebrew
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.
Install
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 Mountain Lion) for Xcode. Open the .dmg file once it's done downloading, and double-click on the .mpkg 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 an 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
Usage
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
##NVM brew install nvm add this to .zshrc
export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh
##Ruby and RBEnv
Ruby does come pre-installed on Mac, but you probably shouldn't be tinkering around with that version. It's best to install a ruby version manager to take care of anything that one might screw up messing around with your system's version of Ruby. Now that we have Homebrew installed, it's as easy as:
$ brew update
$ brew install rbenv ruby-build
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
-
Add
rbenv init
to your shell to enable shims and autocompletion.$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Same as in previous step, use
~/.bashrc
on Ubuntu, or~/.zshrc
for Zsh. -
Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if rbenv was set up:
$ type rbenv #=> "rbenv is a function"
Homebrew Cask
brew install caskroom/cask/brew-cask brew cask install google-chrome
SoundCleod
https://github.com/salomvary/soundcleod
##Maximum Awesome
I originally intended to write my own build script for a lot of this, but Maximum Awesome already does a fantastic job installing iTerm2, Tmux, MacVim and a plethora of other great features!
https://github.com/square/maximum-awesome
$ cd ~/Sites/tmp
$ git clone https://github.com/square/maximum-awesome && cd maximum-awesome
$ rake
Google Chrome
Download: http://google.com/chrome.
$ brew cask install google-chrome
Google Chrome Canary
$ brew cask install google-chrome-canary
Consolas
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.
Git
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.github.com/nicolashery/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.
Sublime Text
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 shorcut 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 $60 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 affect (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.
Vim
Although Sublime Text will be our main editor, it is a good idea to learn some very basic usage of Vim. It is a very popular text editor inside the terminal, and is usually pre-installed on any Unix system.
For example, when you run a Git commit, it will open Vim to allow you to type the commit message.
I suggest you read a tutorial on Vim. Grasping the concept of the two "modes" of the editor, Insert (by pressing i
) and Normal (by pressing Esc
to exit Insert mode), will be the part that feels most unatural. After that it's just remembering a few important keys.
Vim's default settings aren't great, and you could spend a lot of time tweaking your configuration (the .vimrc
file). But if you're like me and just use Vim occasionally, you'll be happy to know that Tim Pope has put together some sensible defaults to quickly get started.
First, install pathogen.vim by running:
$ mkdir -p ~/.vim/autoload ~/.vim/bundle
$ curl -Sso ~/.vim/autoload/pathogen.vim \
https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
Then create a file ~/.vimrc
(you can use $ subl ~/.vimrc
), and paste in the following:
execute pathogen#infect()
syntax on
filetype plugin indent on
And finally, install the Vim "sensible defaults" by running:
$ cd ~/.vim/bundle
$ git clone git://github.com/tpope/vim-sensible.git
With that, Vim will look a lot better next time you open it!
Node.js
Install Node.js with Homebrew:
$ brew update
$ brew install node
The formula also installs the npm package manager. However, as suggested by the Homebrew output, we need to add /usr/local/share/npm/bin
to our path so that npm-installed modules with executables will have them picked up.
To do so, add this line to your ~/.path
file, before the export PATH
line:
PATH=/usr/local/share/npm/bin:$PATH
Open a new terminal for the $PATH
changes to take effect.
We also need to tell npm where to find the Xcode Command Line Tools, by running:
$ sudo xcode-select -switch /usr/bin
Node modules are installed locally in the node_modules
folder of each project by default, but there are at least two that are worth installing globally. Those are CoffeeScript and Grunt:
$ npm install -g coffee-script
$ npm install -g grunt-cli
Npm usage
To install a package:
$ npm install <package> # Install locally
$ npm install -g <package> # Install globally
To install a package and save it in your project's package.json
file:
$ npm install <package> --save
To see what's installed:
$ npm list # Local
$ npm list -g # Global
To find outdated packages (locally or globally):
$ npm outdated [-g]
To upgrade all or a particular package:
$ npm update [<package>]
To uninstall a package:
$ npm uninstall <package>
Heroku
Heroku, if you're not already familiar with it, is a Platform-as-a-Service (PaaS) that makes it really easy to deploy your apps online. There are other similar solutions out there, but Heroku was among the first and is currently the most popular. Not only does it make a developer's life easier, but I find that having Heroku deployment in mind when building an app forces you to follow modern app development best practices.
Install
Assuming that you have an account (sign up if you don't), let's install the Heroku Client for the command-line. Heroku offers a Mac OS X installer, the Heroku Toolbelt, that includes the client. But for these kind of tools, I prefer using Homebrew. It allows us to keep better track of what we have installed. Luckily for us, Homebrew includes a heroku-toolbelt
formula:
$ brew install heroku-toolbelt
The formula might not have the latest version of the Heroku Client, which is updated pretty often. Let's update it now:
$ heroku update
Don't be afraid to run heroku update
every now and then to always have the most recent version.
Usage
Login to your Heroku account using your email and password:
$ heroku login
If this is a new account, and since you don't already have a public SSH key in your ~/.ssh
directory, it will offer to create one for you. Say yes! It will also upload the key to your Heroku account, which will allow you to deploy apps from this computer.
If it didn't offer create the SSH key for you (i.e. your Heroku account already has SSH keys associated with it), you can do so manually by running:
$ mkdir ~/.ssh
$ ssh-keygen -t rsa
Keep the default file name and skip the passphrase by just hitting Enter both times. Then, add the key to your Heroku account:
$ heroku keys:add
Once the key business is done, you're ready to deploy apps! Heroku has a great Getting Started guide, so I'll let you refer to that (the one linked here is for Python, but there is one for every popular language). Heroku uses Git to push code for deployment, so make sure your app is under Git version control. A quick cheat sheet (if you've used Heroku before):
$ cd myapp/
$ heroku create myapp
$ git push heroku master
$ heroku ps
$ heroku logs -t
The Heroku Dev Center is full of great resources, so be sure to check it out!
MongoDB
MongoDB is a popular NoSQL database.
Install
Installing it is very easy through Homebrew:
$ brew update
$ brew install mongo
Usage
In a terminal, start the MongoDB server:
$ mongod
In another terminal, connect to the database with the Mongo shell using:
$ mongo
I'll let you refer to MongoDB's Getting Started guide for more!
Projects folder
This really depends on how you want to organize your files, but I like to put all my version-controlled projects in ~/Sites/personal
. Other documents I may have, or things not yet under version control, I like to put in ~/Dropbox
(if you have Dropbox installed), or ~/Documents
.
Apps
Here is a quick list of some apps I use, and that you might find useful as well:
- Mou: As a developer, most of the stuff you write ends up being in Markdown. In fact, this
README.md
file (possibly the most important file of a GitHub repo) is indeed in Markdown, written in Sublime Text, and I use Marked to preview the results everytime I save. (FREE) - Alfred
- Evernote: If I don't write something down, I'll forget it. As a developer, you learn so many new things every day, and technology keeps changing, it would be insane to want to keep it all in your head. So take notes, sync them to the cloud, and have them on all your devices. To be honest, I switched to Simplenote because I only take text notes, and I got tired of Evernote putting extra spaces between paragraphs when I copy & pasted into other applications. Simplenote is so much better for text notes (and it supports Markdown!). (Both are free)