This document describes how to set up a local developer environment on a new MacBook or iMac. We will set up popular programming languages (for example Node (JavaScript), Python, and Ruby). You may not need all of them for your projects, although I recommend having the first three set up as they always come in handy.
The document assumes you are new to Mac, but can also be useful if you are reinstalling a system and need some reminders. The steps below were tested on macOS High Sierra (10.13.4). But should be suitable for older OS X version.
(Note This is a modified version of the mac-dev-setup found at here. Shamelessly copied and modified for VS Code and AWS needs.)
First thing you need to do, on any OS actually, is update the system! For that: Apple Icon > About This Mac then 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
I recommend checking that basic security settings are enabled. You will be happy to have done so if ever your Mac is lost or stolen.
In Apple Icon > System Preferences:
- Users & Groups: If you haven't already set a password for your user during the initial set up, you should do so now
- Security & Privacy > General: Require password immediately after sleep or screen saver begins (you can keep a grace period of a couple minutes if you prefer, but I like to know that my computer locks as soon as I close it)
- Security & Privacy > FileVault: Make sure FileVault disk encryption is enabled
- iCloud: If you haven't already done so during set up, enable Find My Mac
Install a primary 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).
Install a secondary browser, let's go with Firefox.
Download from www.mozilla.org/firefox. Open the .dmg file once it's done downloading (this will mount the disk image), and drag and drop the Firefox 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).
Install an API development tool, my choice is Postman. But I hear good things about Insomnia as well.
Download from www.getpostman.com. Open the .dmg file once it's done downloading (this will mount the disk image), and drag and drop the Postman 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).
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.
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 iTerm2 > 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. Under the section General set Working Directory to be Reuse previous session's directory. 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 Developer Tools for Xcode. These include compilers that will allow you to build things from source. You can install them directly from the terminal with:
xcode-select --install
Once that is done, we can install Hombrew by copy-pasting the installation command from the Homebrew homepage inside the terminal.
Follow the steps on the screen. You will be prompted for your user password so Homebrew can set appropriate permissions.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"Ref: https://github.com/Homebrew/install
Once installation is complete, you can run the following command to make sure everything works:
brew doctor
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
A nice extension to Homebrew is Homebrew Services. It will automatically launch things like databases when your computer starts, so you don't have to do it manually every time.
To install it, simply run:
brew tap homebrew/services
After installing a service (for example a database), it should automatically add itself to Hombrew Services. If not, you can add it manually with:
brew services <formula>
Start a service with:
brew services start <formula>
At anytime you can view which services are running with:
brew services list
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.
First let's add some color. There are many great color schemes out there, but if you don't know where to start you can try Oceanic Next. Download the iTerm presets for the theme by running:
cd ~/Downloads
curl -O https://raw.githubusercontent.com/mhartington/oceanic-next-iterm/master/Oceanic-Next.itermcolors
Then, in iTerm2 Preferences, under Profiles and Colors, go to Load Presets... > Import..., find and open the Oceanic-Next.itermcolors file we just downloaded. Go back to Load Presets... and select Oceanic Next to activate it. Voila!
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/azjones/macdev/master/.bash_profile
curl -O https://raw.githubusercontent.com/azjones/macdev/master/.bash_prompt
curl -O https://raw.githubusercontent.com/azjones/macdev/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).
Now we have a terminal we can work with!
(Thanks to Mathias Bynens for his awesome dotfiles.)
Mac OS X comes with a pre-installed version of Git, but we'll install our own through Homebrew to allow easy upgrades and not interfere with the system version. To do so, simply run:
brew update
brew install git
When done, to test that it installed fine you can run:
which git
The output should be /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/azjones/macdev/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)
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.
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 project .gitignore files. You can take a look at this repository's .gitignore file for inspiration. You can also set it up in a global .gitignore file by cloning it into your home directory (but you'll want to make sure any collaborators also do it):
cd ~
curl -O https://raw.githubusercontent.com/azjones/macdev/master/.gitignore
Along with the terminal, the IDE is a developer's most important tool. Everyone has their preference, but if you're just getting started and focus modern languages and want something simple, VS Code is a good option.
First, lets download VS Code. 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 VS Code and iTerm. To do so, right-click on the running application and select Options > Keep in Dock.
As with iTerm, VS Code is customizable. Before we do, let's get it working in the command line. Do this by opening the Command Palette ⇧⌘P (View > Command Palette) then type 'shell command' and select Shell Command: Install 'code' command in PATH.
VS Code makes it very easy to customize the IDE just the way you like. And I've added some extensions to get you going. Once you download the extensions bash script, run it. Running it will install the listed extensions. Feel free to update with the extensions that suit your needs.
cd ~
curl -O https://raw.githubusercontent.com/azjones/macdev/master/vscode-extensions.sh
I've also added some user settings that will get you started customizing the IDE UI. Once you've downloaded the user settings json file, copy the content and go back to VS Code and open the Settings panel to paste. Get there by Code > Preferences > Settings or ⌘, as the shortcut.
cd ~
curl -O
https://raw.githubusercontent.com/azjones/macdev/master/vscode-usersettings.json
Let's make VS Code beatiful. As with the terminal we will be going with Oceanic Next color theme. You can install it here. Once installed, be sure to reload VS Code.
OS X, like Linux, ships with Python already installed. But you don't want to mess with the system Python (some system tools rely on it, etc.), so we'll install our own version using pyenv. This will also allow us to manage multiple versions of Python (ex: 2.7 and 3) should we need to.
Install pyenv via Homebrew by running:
brew install pyenv
When finished, you should see instructions to add something to your profile. Open your .bash_profile in the home directory (you can use $ subl ~/.bash_profile), and add the following line:
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fiSave the file and reload it with:
source ~/.bash_profile
We can now list all available Python versions by running:
pyenv install --list
Look for the latest 2.7.x version (or 3.x), and install it:
pyenv install 2.7.13 # the latest version might be different
List the Python versions you have locally with:
pyenv versions
The start (*) should indicate we are still using the system version. We should set the one we installed to be the default:
pyenv global 2.7.13
You should now see that version when running:
python --version
For more information, see the pyenv commands documentation.
pip was also installed by pyenv. It is the package manager for Python.
Here are a couple Pip commands to get you started. To install a Python package:
pip install <package>
To upgrade a package:
pip install --upgrade <package>
To see what's installed:
pip freeze
To uninstall a package:
pip uninstall <package>
virtualenv is a tool that creates an isolated Python environment for each of your projects. For a particular project, instead of installing required packages globally, it is best to install them in an isolated folder, that will be managed by virtualenv.
The advantage is that different projects might require different versions of packages, and it would be hard to manage that if you install packages globally. It also allows you to keep your global site-packages folder clean, containing only big packages that you always need (for example Numpy and Scipy).
Instead of installing and using virtualenv directly, we'll use the dedicated pyenv plugin pyenv-virtualenv which will make things a bit easier for us. Install it via Homebrew:
brew install pyenv-virtualenv
After installation, add the following line to your .bash_profile;
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fiAnd reload it with:
source ~/.bash_profile
Now, let's say you have a project called myproject. You can set up virtualenv for that project and the Python version it uses (for example 2.7.13):
pyenv virtualenv 2.7.13 myproject
See the list of virtualenvs you created with:
pyenv virtualenvs
To use your project's virtualenv, you need to activate it first (in every terminal where you are working on your project):
pyenv activate myproject
You should see a (myproject) appear at the baeginning of your terminal prompt indicating that you are working inside the virtualenv. Now when you install something:
pip install <package>
It will get installed in that virtualenv's folder, and not conflict with other projects.
IPython is an awesome project which provides a much better Python shell than the one you get from running $ python in the command-line. It has many cool functions (running Unix commands from the Python shell, easy copy & paste, creating Matplotlib charts in-line, etc.) and I'll let you refer to the documentation to discover them.
Before we install IPython, we'll need to get some dependencies. Run the following:
$ brew update # Always good to do
$ brew install zeromq # Necessary for pyzmq
$ brew install pyqt # Necessary for the qtconsole
It may take a few minutes to build these.
Once it's done, we can install IPython with all the available options:
$ pip install ipython[zmq,qtconsole,notebook,test]
You can launch IPython from the command line with $ ipython, but what's more interesting is to use its QT Console. Launch the QT Console by running:
$ ipython qtconsole
You can also customize the font it uses:
$ ipython qtconsole --ConsoleWidget.font_family="Consolas" --ConsoleWidget.font_size=13
And since I'm lazy and I don't want to type or copy & paste that all the time, I'm going to create an alias for it. Create a .extra text file in your home directory with $ subl ~/.extra (I've set up .bash_profile to load .extra), and add the following line:
alias ipy='ipython qtconsole --ConsoleWidget.font_family="Consolas" --ConsoleWidget.font_size=13'Open a fresh terminal. Now when you run $ ipy, it will launch the QT Console with your configured options.
To use the in-line Matplotlib functionality (nice for scientific computing), run $ ipy --pylab=inline.
The Numpy and Scipy scientific libraries for Python are always a little tricky to install from source because they have all these dependencies they need to build correctly. Luckily for us, Samuel John has put together some Homebrew formulae to make it easier to install these Python libraries.
First, grab the special formulae (which are not part of Homebrew core):
$ brew tap samueljohn/python
$ brew tap homebrew/science
Then, install the gfortran dependency (now in gcc) which we will need to build the libraries:
$ brew install gcc
Finally, you can install Numpy and Scipy with:
$ brew install numpy
$ brew install scipy
(It may take a few minutes to build.)
The recommended way of installing Node.js and NPM is using Node Version Manager (nvm). I prefer a better solution that is easier to setup and easier to manage. We install node using Homebrew. Then installed the Node package, n.
$ brew install nodeInstalling Node also installs the npm package manager.
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>
Node.js version management: no subshells, no profile setup, no convoluted API, just simple. This is the tool we use in place of nvm.
$ npm i -g nSimply execute n <version> or n latest or n stable to install a version of Node.js.
$ n 8.10Serverless is your toolkit for deploying and operating serverless architectures. Focus on your application, not your infrastructure. A must have for deploying serverless (AWS Lambda) functions.
$ npm i -g serverlessThe pluggable linting utility for JavaScript and JSX. We need this for the VS Code eslint extension.
$ npm i -g eslintLike Python, Ruby is already installed on Unix systems. But we don't want to mess around with that installation. More importantly, we want to be able to use the latest version of Ruby.
When installing Ruby, best practice is to use RVM (Ruby Version Manager) which allows you to manage multiple versions of Ruby on the same machine. Installing RVM, as well as the latest version of Ruby, is very easy. Just run:
curl -sSL https://get.rvm.io | bash -s stable --ruby
When it is done, both RVM and a fresh version of Ruby are installed.
Open a new terminal and run:
type rvm | head -1
You should get the output rvm is a function.
The following command will show you which versions of Ruby you have installed:
rvm list
The one that was just installed, Ruby 2, should be set as default. When managing multiple versions, you switch between them with:
rvm use system # Switch back to system install (ex: 2.0)
rvm use 2.3 --default # Switch to 2.3 and sets it as default
Run the following to make sure the version you want is being used:
which ruby
ruby --version
You can install another version with:
rvm install 2.2
To update RVM itself, use:
rvm get stable
RubyGems, the Ruby package manager, was also installed:
which gem
Update to its latest version with:
gem update --system
To install a "gem" (Ruby package), run:
gem install <gemname>
To install without generating the documentation for each gem (faster):
gem install <gemname> --no-document
To see what gems you have installed:
gem list
To check if any installed gems are outdated:
gem outdated
To update all gems or a particular gem:
gem update [<gemname>]
RubyGems keeps old versions of gems, so feel free to do come cleaning after updating:
gem cleanup
Redis is a blazing fast, in-memory, key-value store, that uses the disk for persistence. It's kind of like a NoSQL database, but there are a lot of cool things that you can do with it that would be hard or inefficient with other database solutions. For example, it's often used as session management or caching by web apps, but it has many other uses.
To install Redis, use Homebrew:
brew update
brew install redis
Start it through Homebrew Services with:
brew services start redis
I'll let you refer to Redis' documentation or other tutorials for more information.
MongoDB is a popular NoSQL database.
Installing it is very easy through Homebrew:
brew update
brew install mongo
Start it through Homebrew Services with:
brew services start mongo
I'll let you refer to MongoDB's Getting Started guide for more!
As it says on the box, Elasticsearch is a "powerful open source, distributed real-time search and analytics engine". It uses an HTTP REST API, making it really easy to work with from any programming language.
You can use elasticsearch for such cool things as real-time search results, autocomplete, recommendations, machine learning, and more.
Elasticsearch runs on Java, so check if you have it installed by running:
java -versionIf Java isn't installed yet, a window will appear prompting you to install it. Go ahead and click "Install".
Next, install elasticsearch with:
$ brew install elasticsearchNote: Elasticsearch also has a plugin program that gets moved to your PATH. I find that too generic of a name, so I rename it to elasticsearch-plugin by running (will need to do that again if you update elasticsearch):
$ mv /usr/local/bin/plugin /usr/local/bin/elasticsearch-pluginBelow I will use elasticsearch-plugin, just replace it with plugin if you haven't followed this step.
As you guessed, you can add plugins to elasticsearch. A popular one is elasticsearch-head, which gives you a web interface to the REST API. Install it with:
$ elasticsearch-plugin --install mobz/elasticsearch-headStart a local elasticsearch server with:
$ elasticsearch -f(The -f option tells it to run in the foreground, so you can stop it with Ctrl+C.)
Test that the server is working correctly by running:
$ curl -XGET 'http://localhost:9200/'If you installed the elasticsearch-head plugin, you can visit its interface at http://localhost:9200/_plugin/head/.
Elasticsearch's documentation is more of a reference. To get started, I suggest reading some of the blog posts linked on this StackOverflow answer.
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, I like to put in ~/Dropbox (if you have Dropbox installed), or ~/Documents.
brew install awscliTo see the options like, changing ComputerName, LocalHostName, HostName
scutil -hscutil --set HostName <the-name-you-want>Here is a quick list of some apps I use, and that you might find useful as well:
- Dropbox: File syncing to the cloud. I put all my documents in Dropbox. It syncs them to all my devices (laptop, mobile, tablet), and serves as a backup as well! (Free for 2GB)
- Google Drive: File syncing to the cloud too! I use Google Docs a lot to collaborate with others (edit a document with multiple people in real-time!), and sometimes upload other non-Google documents (pictures, etc.), so the app comes in handy for that. (Free for 5GB)
- 1Password: Allows you to securely store your login and passwords. Even if you only use a few different passwords (they say you shouldn't!), this is really handy to keep track of all the accounts you sign up for! Also, they have a mobile app so you always have all your passwords with you (syncs with Dropbox). A little pricey though. There are free alternatives. ($50 for Mac app, $18 for iOS app)
- Marked: As a developer, most of the stuff you write ends up being in Markdown. In fact, this
README.mdfile (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. ($4) - 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)
- Mac Dev Setup nicolashery
- Oceanic Next macOS terminal robinbently