diff --git a/.aliases b/.aliases index 8f5c770..05bd9d9 100644 --- a/.aliases +++ b/.aliases @@ -1,18 +1,20 @@ +#!/usr/bin/env bash + # Detect which `ls` flavor is in use if ls --color > /dev/null 2>&1; then # GNU `ls` colorflag="--color" -else # OS X `ls` +else # macOS `ls` colorflag="-G" fi # List all files colorized in long format -alias ll='ls -lh' +alias ll="ls -lF ${colorflag}" # List all files colorized in long format, including dot files -alias la="ls -lha" +alias la="ls -laF ${colorflag}" # List only directories -alias lsd='ls -l | grep "^d"' +alias lsd="ls -lF ${colorflag} | grep --color=never '^d'" # Always use color output for `ls` alias ls="command ls ${colorflag}" diff --git a/.bash_profile b/.bash_profile index 87a2e15..e499081 100644 --- a/.bash_profile +++ b/.bash_profile @@ -1,12 +1,10 @@ -# Add Homebrew `/usr/local/bin` and User `~/bin` to the `$PATH` -PATH=/usr/local/bin:$PATH -PATH=$HOME/bin:$PATH -export PATH +# Add `~/bin` to the `$PATH` +export PATH="$HOME/bin:$PATH"; # Load the shell dotfiles, and then some: # * ~/.path can be used to extend `$PATH`. # * ~/.extra can be used for other settings you don’t want to commit. for file in ~/.{path,bash_prompt,exports,aliases,functions,extra}; do - [ -r "$file" ] && source "$file" -done -unset file \ No newline at end of file + [ -r "$file" ] && [ -f "$file" ] && source "$file"; +done; +unset file; diff --git a/.bash_prompt b/.bash_prompt index f960acc..84a3611 100644 --- a/.bash_prompt +++ b/.bash_prompt @@ -1,56 +1,46 @@ # @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt” # Shamelessly copied from https://github.com/gf3/dotfiles -# Screenshot: http://i.imgur.com/s0Blh.png if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then - export TERM=gnome-256color + export TERM='gnome-256color'; elif infocmp xterm-256color >/dev/null 2>&1; then - export TERM=xterm-256color -fi + export TERM='xterm-256color'; +fi; if tput setaf 1 &> /dev/null; then - tput sgr0 - if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then - # Changed these colors to fit Solarized theme - MAGENTA=$(tput setaf 125) - ORANGE=$(tput setaf 166) - GREEN=$(tput setaf 64) - PURPLE=$(tput setaf 61) - WHITE=$(tput setaf 244) - else - MAGENTA=$(tput setaf 5) - ORANGE=$(tput setaf 4) - GREEN=$(tput setaf 2) - PURPLE=$(tput setaf 1) - WHITE=$(tput setaf 7) - fi - BOLD=$(tput bold) - RESET=$(tput sgr0) + tput sgr0; # reset colors + bold=$(tput bold); + reset=$(tput sgr0); + # Oceanic Next colors + black=$(tput setaf 16); + blue=$(tput setaf 68); + cyan=$(tput setaf 73); + green=$(tput setaf 114); + orange=$(tput setaf 209); + magenta=$(tput setaf 176); + red=$(tput setaf 203); + white=$(tput setaf 66); + yellow=$(tput setaf 221); else - MAGENTA="\033[1;31m" - ORANGE="\033[1;33m" - GREEN="\033[1;32m" - PURPLE="\033[1;35m" - WHITE="\033[1;37m" - BOLD="" - RESET="\033[m" -fi - -export MAGENTA -export ORANGE -export GREEN -export PURPLE -export WHITE -export BOLD -export RESET + bold=''; + reset="\e[0m"; + black="\e[1;30m"; + blue="\e[1;34m"; + cyan="\e[1;36m"; + green="\e[1;32m"; + orange="\e[1;33m"; + magenta="\e[1;35m"; + red="\e[1;31m"; + white="\e[1;37m"; + yellow="\e[1;33m"; +fi; function parse_git_dirty() { - [[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && echo "*" + [[ $(git status 2> /dev/null | tail -n1) != *"nothing to commit"* ]] && echo "*" } function parse_git_branch() { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" } -export PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]" -export PS2="\[$ORANGE\]→ \[$RESET\]" \ No newline at end of file +PS1="\[${bold}\]\[$green\]\w\[$white\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$magenta\]\$(parse_git_branch)\[$white\]\n\$ \[$reset\]" diff --git a/.gitconfig b/.gitconfig index b27880d..1c0a6be 100644 --- a/.gitconfig +++ b/.gitconfig @@ -7,7 +7,8 @@ hist = log --graph --pretty=format:'%Cred%h%Creset %s%C(yellow)%d%Creset %Cgreen(%cr)%Creset [%an]' --abbrev-commit --date=relative [color] - # Use colors in Git commands that are capable of colored output when outputting to the terminal + # Use colors in Git commands that are capable of colored output when + # outputting to the terminal. (This is the default setting in Git ≥ 1.8.4.) ui = auto [color "branch"] current = yellow reverse @@ -22,9 +23,3 @@ added = yellow changed = green untracked = cyan - -# Use `origin` as the default remote on the `master` branch in all cases -[branch "master"] - remote = origin - merge = refs/heads/master - diff --git a/.gitignore b/.gitignore index 1b8ce79..628b71c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,11 +9,3 @@ Thumbs.db # Files that might appear on external disks .Spotlight-V100 .Trashes - -# Compiled Python files -*.pyc - -# Application specific files -venv -node_modules -.sass-cache \ No newline at end of file diff --git a/README.md b/README.md index 27c8d04..a3e3b87 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,24 @@ -# Mac OS X Dev Setup +# macOS Dev Setup -This document describes how I set up my developer environment on a new MacBook or iMac. We will set up [Node](http://nodejs.org/) (JavaScript), [Python](http://www.python.org/), and [Ruby](http://www.ruby-lang.org/) environments, mainly for JavaScript and Python development. Even if you don't program in all three, 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. +This document describes how I set up my developer environment on a new MacBook or iMac. We will set up popular programming languages (for example [Node](http://nodejs.org/) (JavaScript), [Python](http://www.python.org/), and [Ruby](http://www.ruby-lang.org/)). You may not need all of them for your projects, although I recommend having them set up as they always come in handy. -The document assumes you are new to Mac. The steps below were tested on **OS X Mountain Lion**. +The document assumes you are new to Mac, but can also be useful if you are reinstalling a system and need some reminder. The steps below were tested on **macOS High Sierra** (10.13), but should work for more recent versions as well. -If you have any comments or suggestions, feel free to give me a shout [on Twitter](https://twitter.com/nicolahery)! +**Contributing**: If you find any mistakes in the steps described below, or if any of the commands are outdated, do let me know! For any other suggestions, please understand if I don't include everything. This guide was originally written for some friends getting started with programming on a Mac, and as a personal reference for myself. I'm trying to keep it simple! - [System update](#system-update) - [System preferences](#system-preferences) -- [Google Chrome](#google-chrome) +- [Security](#security) - [iTerm2](#iterm2) - [Homebrew](#homebrew) -- [Consolas](#consolas) -- [Beautiful terminal](#beautiful-terminal) -- [iTerm2](#iterm2) - [Git](#git) -- [Sublime Text](#sublime-text) +- [Visual Studio Code](#visual-studio-code) - [Vim](#vim) - [Python](#python) -- [Virtualenv](#virtualenv) -- [IPython](#ipython) -- [Numpy and Scipy](#numpy-and-scipy) -- [MySQL](#mysql) - [Node.js](#nodejs) -- [JSHint](#jshint) -- [Ruby and RVM](#ruby-and-rvm) -- [LESS](#less) +- [Ruby](#ruby) - [Heroku](#heroku) -- [MongoDB](#mongodb) +- [PostgreSQL](#postgresql) - [Redis](#redis) - [Elasticsearch](#elasticsearch) - [Projects folder](#projects-folder) @@ -35,11 +26,11 @@ If you have any comments or suggestions, feel free to give me a shout [on Twitte ## System update -First thing you need to do, on any OS actually, is update the system! For that: **Apple Icon > Software Update...** +First thing you need to do, on any OS actually, is update the system! For that: **Apple Icon > About This Mac** then **Software Update...**. ## System preferences -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. +If this is a new computer, there are a couple of 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**: @@ -48,743 +39,761 @@ In **Apple Icon > System Preferences**: - Keyboard > Delay Until Repeat > Short (all the way to the right) - Dock > Automatically hide and show the Dock -## Google Chrome +## Security + +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. -Install your favorite browser, mine happens to be Chrome. +In **Apple Icon > System Preferences**: -Download from [www.google.com/chrome](https://www.google.com/intl/en/chrome/browser/). 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**). +- 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 ## iTerm2 -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](http://www.iterm2.com/) (the newest version, even if it says "beta release"). +### Install + +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](http://www.iterm2.com/). 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**. +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**. Finally, under the section **Window**, change the size to something better, like **Columns: 125** and **Rows: 35**. +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. +When done, hit the red "X" in the upper left (saving is automatic in macOS preference panes). Close the window and open a new one to see the size change. -## Homebrew +### Beautiful terminal -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](http://brew.sh/). +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. -### Install +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 [Atom One Dark](https://github.com/nathanbuchar/atom-one-dark-terminal). Download the iTerm presets for the theme by running: -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. +``` +cd ~/Downloads +curl -o "Atom One Dark.itermcolors" https://raw.githubusercontent.com/nathanbuchar/atom-one-dark-terminal/master/scheme/iterm/One%20Dark.itermcolors +curl -o "Atom One Light.itermcolors" https://raw.githubusercontent.com/nathanbuchar/atom-one-dark-terminal/master/scheme/iterm/One%20Light.itermcolors +``` -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](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. +Then, in **iTerm2 Preferences**, under **Profiles** and **Colors**, go to **Color Presets... > Import...**, find and open the **Atom One Dark.itermcolors** file we just downloaded. Repeat these steps for **Atom One Light.itermcolors**. Now open **Color Presets...** again and select **Atom One Dark** to activate the dark theme (or choose the light them if that's your preference). -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. +Not a lot of colors yet. We need to tweak a little bit our Unix user's profile for that. This is done (on macOS and Linux), in the `~/.bash_profile` text file (`~` stands for the user's home directory). -**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. +We'll come back to the details of that later, but for now, just download the files [.bash_profile](https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_profile), [.bash_prompt](https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_prompt), [.aliases](https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.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): -Finally, we can install Hombrew! In the terminal paste the following line (without the `$`), hit **Enter**, and follow the steps on the screen: +``` +cd ~ +curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_profile +curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_prompt +curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.aliases +``` - $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +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`). -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: +Now we have a terminal we can work with! - $ echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile +(Thanks to Mathias Bynens for his awesome [dotfiles](https://github.com/mathiasbynens/dotfiles).) -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: +## Homebrew - $ brew doctor - -### Usage +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 macOS is [Homebrew](http://brew.sh/). -To install a package (or **Formula** in Homebrew vocabulary) simply type: - - $ brew install - -To update Homebrew's directory of formulae, run: +### Install - $ 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): +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: - $ cd /usr/local - $ git fetch origin - $ git reset --hard origin/master +``` +xcode-select --install +``` -To see if any of your packages need to be updated: +Once that is done, we can install Homebrew by copy-pasting the installation command from the [Homebrew homepage](http://brew.sh/) inside the terminal: - $ brew outdated - -To update a package: +``` +/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +``` - $ brew upgrade - -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: +Follow the steps on the screen. You will be prompted for your user password so Homebrew can set up the appropriate permissions. - $ brew cleanup +Once installation is complete, you can run the following command to make sure everything works: -To see what you have installed (with their version numbers): +``` +brew doctor +``` - $ brew list --versions +### Usage -## Consolas +To install a package (or **Formula** in Homebrew vocabulary) simply type: -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. +``` +brew install +``` -There are two ways we can install it. If you bought **Microsoft Office for Mac**, install that and Consolas will be installed as well. +To see if any of your packages need to be updated: -If you don't have Office, follow these steps: +``` +brew outdated +``` - $ 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 +To update a package: -And click **Install Font**. Thanks to Alexander Zhuravlev for his [post](http://blog.ikato.com/post/15675823000/how-to-install-consolas-font-on-mac-os-x). +``` +brew upgrade +``` -## Beautiful terminal +Homebrew keeps older versions of packages installed, in case you want to rollback. That rarely is necessary, so you can do some cleanup to get rid of those old versions: -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. +``` +brew cleanup +``` -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**. +To see what you have installed (with their version numbers): -Now let's add some color. I'm a big fan of the [Solarized](http://ethanschoonover.com/solarized) color scheme. It is supposed to be scientifically optimal for the eyes. I just find it pretty. +``` +brew list --versions +``` -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: +### Homebrew Services -- 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! +A nice extension to Homebrew is [Homebrew Services](https://github.com/Homebrew/homebrew-services). It will automatically launch things like databases when your computer starts, so you don't have to do it manually every time. -**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**. +Homebrew Services will automatically install itself the first time you run it, so there is nothing special to do. -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). +After installing a service (for example a database), it should automatically add itself to Homebrew Services. If not, you can add it manually with: -We'll come back to the details of that later, but for now, just download the files [.bash_profile](https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_profile), [.bash_prompt](https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_prompt), [.aliases](https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.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): +``` +brew services +``` - $ cd ~ - $ curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_profile - $ curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_prompt - $ curl -O https://raw.githubusercontent.com/nicolashery/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`). +Start a service with: -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. +``` +brew services start +``` -Now we have a terminal we can work with! +At anytime you can view which services are running with: -(Thanks to Mathias Bynens for his awesome [dotfiles](https://github.com/mathiasbynens/dotfiles).) +``` +brew services list +``` ## Git -What's a developer without [Git](http://git-scm.com/)? To install, simply run: +macOS comes with a pre-installed version of [Git](http://git-scm.com/), 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 install git +``` - $ 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`. +``` +which git +``` + +The output should be `/usr/local/bin/git`. Let's set up some basic configuration. Download the [.gitconfig](https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.gitconfig) file to your home directory: - $ cd ~ - $ curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.gitconfig +``` +cd ~ +curl -O https://raw.githubusercontent.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](https://github.com/) and [Heroku](http://www.heroku.com/)): - $ git config --global user.name "Your Name Here" - $ git config --global user.email "your_email@youremail.com" +``` +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](https://help.github.com/articles/set-up-git): +On a Mac, it is important to remember to add `.DS_Store` (a hidden macOS system file that's put in folders) to your project `.gitignore` files. You also set up a global `.gitignore` file, located for instance in your home directory (but you'll want to make sure any collaborators also do it): - $ 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](https://github.com/nicolashery/mac-dev-setup/blob/master/.gitignore) file for inspiration. - -## Sublime Text +``` +cd ~ +curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.gitignore +git config --global core.excludesfile ~/.gitignore +``` -With the terminal, the text editor is a developer's most important tool. Everyone has their preferences, but unless you're a hardcore [Vim](http://en.wikipedia.org/wiki/Vim_(text_editor)) user, a lot of people are going to tell you that [Sublime Text](http://www.sublimetext.com/) is currently the best one out there. +## Visual Studio Code -Go ahead and [download](http://www.sublimetext.com/) it. Open the **.dmg** file, drag-and-drop in the **Applications** folder, you know the drill now. Launch the application. +With the terminal, the text editor is a developer's most important tool. Everyone has their preferences, but if you're just getting started and looking for something simple that works, [Visual Studio Code](https://code.visualstudio.com/) is a pretty good option. -**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**. +Go ahead and [download](https://code.visualstudio.com/Download) it. Open the **.dmg** file, drag-and-drop in the **Applications** folder, you know the drill now. Launch the application. -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](http://www.sublimetext.com/buy) this awesome tool. :) +**Note**: At this point I'm going to create a shortcut on the macOS Dock for both for Visual Studio Code and iTerm. To do so, right-click on the running application and select **Options > Keep in Dock**. -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: +Just like the terminal, let's configure our editor a little. Go to **Code > Preferences > Settings**. In the very top-right of the interface you should see an icon with brackets that appeared **{ }** (on hover, it should say "Open Settings (JSON)"). Click on it, and paste the following: ```json { - "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 + "editor.tabSize": 2, + "editor.rulers": [80], + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true, + "workbench.editor.enablePreview": false } ``` - + 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: +Pasting the above JSON snippet was handy to quickly customize things, but for further setting changes feel free to search in the "Settings" panel that opened first (shortcut **Cmd+,**). When you're happy with your setup, you can save the JSON to quickly restore it on a new machine. -```json -{ - "tab_size": 4 -} +If you remember only one keyboard shortcut in VS Code, it should be **Cmd+Shift+P**. This opens the **Command Palette**, from which you can run pretty much anything. + +Let's open the command palette now, and search for `Shell Command: Install 'code' command in PATH`. Hit enter when it shows up. This will install the command-line tool `code` to quickly open VS Code from the terminal. When in a projects directory, you'll be able to run: + +``` +cd myproject/ +code . ``` -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. +VS Code is very extensible. To customize it further, open the **Extensions** tab on the left. -A popular Theme is the [Soda Theme](https://github.com/buymeasoda/soda-theme). To install it, run: +Let's do that now to customize the color of our editor. Search for the [Atom One Dark Theme](https://marketplace.visualstudio.com/items?itemName=akamud.vscode-theme-onedark) extension, select it and click **Install**. Repeat this for the [Atom One Light Theme](https://marketplace.visualstudio.com/items?itemName=akamud.vscode-theme-onelight). - $ 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: +Finally, activate the theme by going to **Code > Preferences > Color Theme** and selecting **Atom One Dark** (or **Atom One Light** if that is your preference). - "theme": "Soda Dark.sublime-theme", - "soda_classic_tabs": true +## Vim -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**). +Although VS Code will be our main editor, it is a good idea to learn some very basic usage of [Vim](http://www.vim.org/). It is a very popular text editor inside the terminal, and is usually pre-installed on any Unix system. -The Soda Theme page also offers some [extra color schemes](https://github.com/buymeasoda/soda-theme#syntax-highlighting-colour-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. +For example, when you run a Git commit, it will open Vim to allow you to type the commit message. -Sublime Text 2 already supports syntax highlighting for a lot of languages. I'm going to install a couple that are missing: +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 unnatural. Also, it is good to know that typing `:x` when in Normal mode will save and exit. After that, it's just remembering a few important keys. - $ 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 +Vim's default settings aren't great, and you could spend a lot of time tweaking your configuration (the `.vimrc` file). But if you only use Vim occasionally, you'll be happy to know that [Tim Pope](https://github.com/tpope) has put together some sensible defaults to quickly get started. -Let's create a shortcut so we can launch Sublime Text from the command-line: +Using Vim's built-in package support, install these settings by running: - $ cd ~ - $ mkdir bin - $ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl +``` +mkdir -p ~/.vim/pack/tpope/start +cd ~/.vim/pack/tpope/start +git clone https://tpope.io/vim/sensible.git +``` -Now I can open a file with `$ subl myfile.py` or start a new project in the current directory with `$ subl .`. Pretty cool. +With that, Vim will look a lot better next time you open it! -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](http://wbond.net/sublime_packages/package_control/installation). +## Python -## Vim +macOS, like Linux, ships with [Python](http://python.org/) 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](https://github.com/yyuu/pyenv). This will also allow us to manage multiple versions of Python (ex: 2.7 and 3) should we need to. -Although Sublime Text will be our main editor, it is a good idea to learn some very basic usage of [Vim](http://www.vim.org/). It is a very popular text editor inside the terminal, and is usually pre-installed on any Unix system. +Install `pyenv` via Homebrew by running: -For example, when you run a Git commit, it will open Vim to allow you to type the commit message. +``` +brew install pyenv +``` -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 unnatural. After that it's just remembering a few important keys. +When finished, you should see instructions to add something to your profile. Open your `.bash_profile` in the home directory (you can use `code ~/.bash_profile`), and add the following line: -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](https://github.com/tpope) has put together some sensible defaults to quickly get started. +```bash +if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)"; fi +``` -First, install [pathogen.vim](https://github.com/tpope/vim-pathogen) by running: +Save the file and reload it with: - $ mkdir -p ~/.vim/autoload ~/.vim/bundle && \ - curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim +``` +source ~/.bash_profile +``` -Then create a file `~/.vimrc` (you can use `$ subl ~/.vimrc`), and paste in the following: +Before installing a new Python version, the [pyenv wiki](https://github.com/pyenv/pyenv/wiki) recommends having a few dependencies available: - execute pathogen#infect() - syntax on - filetype plugin indent on +``` +brew install openssl readline sqlite3 xz zlib +``` -And finally, install the Vim "sensible defaults" by running: +We can now list all available Python versions by running: - $ cd ~/.vim/bundle - $ git clone git://github.com/tpope/vim-sensible.git +``` +pyenv install --list +``` -With that, Vim will look a lot better next time you open it! +Look for the latest 3.x version (or 2.7.x), and install it (replace the `.x.x` with actual numbers): -## Python +``` +pyenv install 3.x.x +``` -OS X, like Linux, ships with [Python](http://python.org/) 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 with Homebrew. It will also allow us to get the very latest version of Python 2.7. +List the Python versions you have locally with: -The following command will install Python 2.7 and any dependencies required (it can take a few minutes to build everything): +``` +pyenv versions +``` - $ brew install python - -When finished, you should get a summary in the terminal. Running `$ which python` should output `/usr/local/bin/python`. +The star (`*`) should indicate we are still using the `system` version, which is the default. I recommend leaving it as the default as some [Node.js](https://nodejs.org/en/) packages will use it in their installation process. -It also installed [Pip]() (and its dependency [Distribute]()), which is the package manager for Python. Let's upgrade them both: +You can switch your current terminal to another Python version with: - $ pip install --upgrade distribute - $ pip install --upgrade pip - -Executable scripts from Python packages you install will be put in `/usr/local/share/python`, so let's add it to the `$PATH`. To do so, we'll create a `.path` text file in the home directory (I've already set up `.bash_profile` to call this file): +``` +pyenv shell 3.x.x +``` - $ cd ~ - $ subl .path - -And add these lines to `.path`: +You should now see that version when running: -```bash -PATH=/usr/local/share/python:$PATH -export PATH ``` - -Save the file and open a new terminal to take the new `$PATH` into account (everytime you open a terminal, `.bash_profile` gets loaded). +python --version +``` + +In a project directory, you can use: + +``` +pyenv local 3.x.x +``` -### Pip Usage +This will save that project's Python version to a `.python-version` file. Next time you enter the project's directory from a terminal, `pyenv` will automatically load that version for you. + +For more information, see the [pyenv commands](https://github.com/yyuu/pyenv/blob/master/COMMANDS.md) documentation. + +### pip + +[pip](https://pip.pypa.io) 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 +``` +pip install +``` To upgrade a package: - $ pip install --upgrade - +``` +pip install --upgrade +``` + To see what's installed: - $ pip freeze - +``` +pip freeze +``` + To uninstall a package: - $ pip uninstall +``` +pip uninstall +``` -## Virtualenv +### virtualenv -[Virtualenv](http://www.virtualenv.org/) 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 in the project (say a folder named `venv`), that will be managed by virtualenv. +[virtualenv](https://virtualenv.pypa.io) is a tool that creates an isolated Python environment for each of your projects. -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 `/usr/local/lib/python2.7/site-packages` folder clean, containing only critical or big packages that you always need (like IPython, Numpy). +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. -### Install +Instead of installing and using `virtualenv` directly, we'll use the dedicated `pyenv` plugin [pyenv-virtualenv](https://github.com/yyuu/pyenv-virtualenv) which will make things a bit easier for us. Install it via Homebrew: -To install virtualenv, simply run: +``` +brew install pyenv-virtualenv +``` - $ pip install virtualenv +After installation, add the following line to your `.bash_profile`: -### Usage +```bash +if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi +``` -Let's say you have a project in a directory called `myproject`. To set up virtualenv for that project: +And reload it with: - $ cd myproject/ - $ virtualenv venv --distribute - -If you want your virtualenv to also inherit globally installed packages (like IPython or Numpy mentioned above), use: +``` +source ~/.bash_profile +``` - $ virtualenv venv --distribute --system-site-packages +Now, let's say you have a project called `myproject`. You can set up a virtualenv for that project and the Python version it uses (replace `3.x.x` with the version you want): -These commands create a `venv` subdirectory in your project where everything is installed. You need to **activate** it first though (in every terminal where you are working on your project): +``` +pyenv virtualenv 3.x.x myproject +``` - $ source venv/bin/activate - -You should see a `(venv)` appear at the beginning of your terminal prompt indicating that you are working inside the virtualenv. Now when you install something: +See the list of virtualenvs you created with: - $ pip install +``` +pyenv virtualenvs +``` -It will get installed in the `venv` folder, and not conflict with other projects. +To use your project's virtualenv, you need to **activate** it first (in every terminal where you are working on your project): -**Important**: Remember to add `venv` to your project's `.gitignore` file so you don't include all of that in your source code! +``` +pyenv activate myproject +``` -As mentioned earlier, I like to install big packages (like Numpy), or packages I always use (like IPython) globally. All the rest I install in a virtualenv. +If you run `pyenv virtualenvs` again, you should see a star (`*`) next to the active virtualenv. -## IPython +Now when you install something: -[IPython](http://ipython.org/) 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](http://ipython.org/ipython-doc/stable/index.html) to discover them. +``` +pip install +``` -### Install +It will get installed in that virtualenv's folder, and not conflict with other projects. -Before we install IPython, we'll need to get some dependencies. Run the following: +You can also set your project's `.python-version` to point to a virtualenv you created: - $ 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. +``` +pyenv local myproject +``` -Once it's done, we can install IPython with all the available options: +Next time you enter that project's directory, `pyenv` will automatically load the virtualenv for you. - $ pip install ipython[zmq,qtconsole,notebook,test] +### Anaconda and Miniconda -### Usage +The Anaconda/Miniconda distributions of Python come with many useful tools for scientific computing. -You can launch IPython from the command line with `$ ipython`, but what's more interesting is to use its [QT Console](http://ipython.org/ipython-doc/stable/interactive/qtconsole.html). Launch the QT Console by running: +You can install them using `pyenv`, for example (replace `x.x.x` with an actual version number): - $ ipython qtconsole - -You can also customize the font it uses: +``` +pyenv install miniconda3-x.x.x +``` - $ 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: +After loading an Anaconda or Miniconda Python distribution into your shell, you can create [conda](https://docs.conda.io/) environments (which are similar to virtualenvs): -```bash -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. +pyenv shell miniconda3-x.x.x +conda create --name mycondaproject +conda activate mycondaproject +``` -To use the in-line Matplotlib functionality (nice for scientific computing), run `$ ipy --pylab=inline`. +Install packages, for example the [Jupyter Notebook](https://jupyter.org/), using: -## Numpy and Scipy +``` +conda install jupyter +``` -The [Numpy](http://numpy.scipy.org/) and [Scipy](http://www.scipy.org/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](http://www.samueljohn.de/) has put together some [Homebrew formulae](https://github.com/samueljohn/homebrew-python) to make it easier to install these Python libraries. +You should now be able to run the notebook: -First, grab the special formulae (which are not part of Homebrew core): +``` +jupyter notebook +``` - $ brew tap samueljohn/python - $ brew tap homebrew/science - -Then, install the `gfortran` dependency (now in `gcc`) which we will need to build the libraries: +Deactivate the environment, and return to the default Python version with: - $ brew install gcc - -Finally, you can install Numpy and Scipy with: +``` +conda deactivate +pyenv shell --unset +``` - $ brew install numpy - $ brew install scipy - -(It may take a few minutes to build.) +### Known issue: `gettext` not found by `git` after installing Anaconda/Miniconda -## MySQL +If you installed an Anaconda/Miniconda distribution, you may start seeing an error message when using certain `git` commands, similar to this one: -### Install +``` +pyenv: gettext.sh: command not found -We will install [MySQL](http://www.mysql.com/) using Homebrew, which will also install some header files needed for MySQL bindings in different programming languages (MySQL-Python for one). +The `gettext.sh' command exists in these Python versions: + miniconda3-latest +``` -To install, run: +If that is the case, you can use the following [workaround](https://github.com/pyenv/pyenv/issues/688#issuecomment-428675578): - $ brew update # Always good to do - $ brew install mysql +``` +brew install gettext +``` -As you can see in the ouput from Homebrew, before we can use MySQL we first need to set it up with: +Then add this line to your `.bash_profile`: - $ unset TMPDIR - $ mkdir /usr/local/var - $ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp +```bash +# Workaround for: https://github.com/pyenv/pyenv/issues/688#issuecomment-428675578 +export PATH="/usr/local/opt/gettext/bin:$PATH" +``` -### Usage +## Node.js -To start the MySQL server, use the `mysql.server` tool: +The recommended way to install [Node.js](http://nodejs.org/) is to use [nvm](https://github.com/creationix/nvm) (Node Version Manager) which allows you to manage multiple versions of Node.js on the same machine. - $ mysql.server start - -To stop it when you are done, run: +Install `nvm` by copy-pasting the [install script command](https://github.com/creationix/nvm#install--update-script) into your terminal. - $ mysql.server stop - -You can see the different commands available for `mysql.server` with: +Once that is done, open a new terminal and verify that it was installed correctly by running: - $ mysql.server --help - -To connect with the command-line client, run: +``` +command -v nvm +``` - $ mysql -uroot - -(Use `exit` to quit the MySQL shell.) +View the all available stable versions of Node with: -**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'`. +``` +nvm ls-remote --lts +``` -### MySQL Workbench +Install the latest stable version with: -In terms of a GUI client for MySQL, I'm used to the official and free [MySQL Workbench](http://www.mysql.com/products/workbench/). But feel free to use whichever you prefer. +``` +nvm install node +``` -You can find the MySQL Workbench download [here](http://www.mysql.com/downloads/workbench/). (**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.) +It will also set the first version installed as your default version. You can install another specific version, for example Node 10, with: -## Node.js +``` +nvm install 10 +``` -Install [Node.js](http://nodejs.org/) with Homebrew: +And switch between versions by using: - $ brew update - $ brew install node - -The formula also installs the [npm](https://npmjs.org/) 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. +``` +nvm use 10 +nvm use default +``` -To do so, add this line to your `~/.path` file, before the `export PATH` line: +See which versions you have install with: -```bash -PATH=/usr/local/share/npm/bin:$PATH ``` - -Open a new terminal for the `$PATH` changes to take effect. +nvm ls +``` + +Change the default version with: -We also need to tell npm where to find the Xcode Command Line Tools, by running: +``` +nvm alias default 10 +``` - $ sudo xcode-select -switch /usr/bin +In a project's directory you can create a `.nvmrc` file containing the Node.js version the project uses, for example: -(If Xcode Command Line Tools were installed by Xcode, try instead:) +``` +echo "10" > .nvmrc +``` - $ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer +Next time you enter the project's directory from a terminal, you can load the correct version of Node.js by running: -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](http://coffeescript.org/) and [Grunt](http://gruntjs.com/): +``` +nvm use +``` - $ npm install -g coffee-script - $ npm install -g grunt-cli +### npm -### Npm usage +Installing Node also installs the [npm](https://npmjs.org/) package manager. To install a package: - $ npm install # Install locally - $ npm install -g # Install globally +``` +npm install # Install locally +npm install -g # Install globally +``` To install a package and save it in your project's `package.json` file: - $ npm install --save +``` +npm install --save +``` To see what's installed: - $ npm list # Local - $ npm list -g # Global +``` +npm list --depth 1 # Local packages +npm list -g --depth 1 # Global packages +``` To find outdated packages (locally or globally): - $ npm outdated [-g] +``` +npm outdated [-g] +``` To upgrade all or a particular package: - $ npm update [] +``` +npm update [] +``` To uninstall a package: - $ npm uninstall - -##JSHint - -JSHint is a JavaScript developer's best friend. - -If the extra credit assignment to install Sublime Package Manager was completed, JSHint can be run as part of Sublime Text. - -Install JSHint via npm (global install preferred) - - $ npm install -g jshint - -Follow additional instructions on the [JSHint Package Manager page](https://sublime.wbond.net/packages/JSHint) or [build it manually](https://github.com/jshint/jshint). +``` +npm uninstall --save +``` -## Ruby and RVM +## Ruby Like Python, [Ruby](http://www.ruby-lang.org/) 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. ### Install -When installing Ruby, best practice is to use [RVM](https://rvm.io/) (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: +The recommended way to install Ruby is to use [rbenv](https://github.com/rbenv/rbenv), which allows you to manage multiple versions of Ruby on the same machine. You can install `rbenv` with Homebrew: + +``` +brew install rbenv +``` - $ curl -L https://get.rvm.io | bash -s stable --ruby - -When it is done, both RVM and a fresh version of Ruby 2.0 are installed. The following line was also automatically added to your `.bash_profile`: +After installation, add the following line to your `.bash_profile`: ```bash -[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* +eval "$(rbenv init -)" ``` -I prefer to move that line to the `.extra` file, keeping my `.bash_profile` clean. I suggest you do the same. +And reload it with: -After that, start a new terminal and run: - - $ type rvm | head -1 - -You should get the output `rvm is a function`. +``` +source ~/.bash_profile +``` ### Usage -The following command will show you which versions of Ruby you have installed: - - $ rvm list +The following command will show you which versions of Ruby are available to install: -The one that was just installed, Ruby 2.0, should be set as default. When managing multiple versions, you switch between them with: - - $ rvm use system # Switch back to system install (1.8) - $ rvm use 2.0.0 --default # Switch to 2.0.0 and sets it as default - -Run the following to make sure the version you want is being used (in our case, the just-installed Ruby 1.9.3): - - $ which ruby - $ ruby --version +``` +rbenv install --list +``` -You can install another version with: +You can find the latest version in that list and install it with (replace `.x.x` with actual version numbers): - $ rvm install 1.9.3 +``` +rbenv install 2.x.x +``` -To update RVM itself, use: +Run the following to see which versions you have installed: - $ rvm get stable - -[RubyGems](http://rubygems.org/), the Ruby package manager, was also installed: - - $ which gem - -Update to its latest version with: +``` +rbenv versions +``` - $ gem update --system - -To install a "gem" (Ruby package), run: +The start (`*`) will show you that we are currently using the default `system` version. You can switch your terminal to use the one you just installed: - $ gem install - -To install without generating the documentation for each gem (faster): +``` +rbenv shell 2.x.x +``` - $ gem install --no-document - -To see what gems you have installed: +You can also set it as the default version if you want: - $ gem list - -To check if any installed gems are outdated: +``` +rbenv global 2.x.x +``` - $ gem outdated - -To update all gems or a particular gem: +In a specific project's directory, you can ask `rbenv` to create a `.ruby-version` file. Next time you enter that project's directory from the terminal, it will automatically load the correct Ruby version: - $ gem update [] - -RubyGems keeps old versions of gems, so feel free to do come cleaning after updating: +``` +rbenv local 2.x.x +``` - $ gem cleanup - -I mainly use Ruby for the CSS pre-processor [Compass](http://compass-style.org/), which is built on top of [Sass](http://sass-lang.com/): +Check anytime which version you are using with: - $ gem install compass --no-document +``` +rbenv version +``` -## LESS +See [rbenv's command reference](https://github.com/rbenv/rbenv#command-reference) for more information. -CSS preprocessors are becoming quite popular, the most popular processors are [LESS](http://lesscss.org/) and [SASS](http://sass-lang.com). Preprocessing is a lot like compiling code for CSS. It allows you to reuse CSS in many different ways. Let's start out with using LESS as a basic preprocessor, it's used by a lot of popular CSS frameworks like [Bootstrap](http://getbootstrap.com/). +### RubyGems & Bundler -### Install +[RubyGems](http://rubygems.org/), the Ruby package manager, was also installed: -To install LESS you have to use NPM / Node, which you installed earlier using Homebrew. In the terminal use: +``` +which gem +``` - $ npm install less --global +The first thing you want to do after installing a new Ruby version is to install [Bundler](https://bundler.io/). This tool will allow you to set up separate environments for your different Ruby projects, so their required gem versions won't conflict with each other. Install Bundler with: -Note: the `--global` flag is optional but it prevents having to mess around with file paths. You can install without the flag, just know what you're doing. +``` +gem install bundler +``` -You can check that it installed properly by using: +In a new Ruby project directory, create a new `Gemfile` with: - $ lessc --version +``` +bundle init +``` -This should output some information about the compiler: +Add a dependency to the `Gemfile`, for example the [Jekyll]() static site generator: - lessc 1.5.1 (LESS Compiler) [JavaScript] +```ruby +source "https://rubygems.org" -Okay, LESS is installed and running. Great! +gem "jekyll" +``` -### Usage +Then install the project's dependencies with: -There's a lot of different ways to use LESS. Generally I use it to compile my stylesheet locally. You can do that by using this command in the terminal: +``` +bundle install +``` - $ lessc template.less template.css +Make sure you check in both the `Gemfile` and `Gemfile.lock` into your Git repository. -The two options are the "input" and "output" files for the compiler. The command looks in the current directory for the LESS stylesheet, compiles it, and outputs it to the second file in the same directory. You can add in paths to keep your project files organized: +Update a specific dependency with: - $ lessc less/template.less css/template.css +``` +bundle update +``` -Read more about LESS on their page here: http://lesscss.org/ +For more information, see the [Bundler documentation](https://bundler.io/docs.html). ## Heroku -[Heroku](http://www.heroku.com/), if you're not already familiar with it, is a [Platform-as-a-Service](http://en.wikipedia.org/wiki/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](http://www.12factor.net/). - -### Install +[Heroku](http://www.heroku.com/) is a [Platform-as-a-Service](http://en.wikipedia.org/wiki/Platform_as_a_service) (PaaS) that makes it really easy to deploy your apps. There are other similar solutions out there, but Heroku is among 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](http://www.12factor.net/). -Assuming that you have an account (sign up if you don't), let's install the [Heroku Client](https://devcenter.heroku.com/articles/using-the-cli) for the command-line. Heroku offers a Mac OS X installer, the [Heroku Toolbelt](https://toolbelt.heroku.com/), 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: +Assuming that you have an account (sign up if you don't), let's install the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli): - $ 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 +``` +brew tap heroku/brew +brew install heroku +``` -Login to your Heroku account using your email and password: +Login to your Heroku account using: - $ 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. +``` +heroku login +``` -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: +(This will prompt you to open a page in your web browser and log in to your Heroku account.) - $ 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: +Once logged-in, you're ready to deploy apps! Heroku has great [Getting Started](https://devcenter.heroku.com/start) guides for different languages, so I'll let you refer to that. 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): - $ heroku keys:add - -Once the key business is done, you're ready to deploy apps! Heroku has a great [Getting Started](https://devcenter.heroku.com/articles/python) 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 +``` - $ cd myapp/ - $ heroku create myapp - $ git push heroku master - $ heroku ps - $ heroku logs -t - The [Heroku Dev Center](https://devcenter.heroku.com/) is full of great resources, so be sure to check it out! -## MongoDB +## PostgreSQL -[MongoDB](http://www.mongodb.org/) is a popular [NoSQL](http://en.wikipedia.org/wiki/NoSQL) database. +[PostgreSQL](https://www.postgresql.org/) is a popular relational database, and Heroku has first-class support for it. -### Install +Install PostgreSQL using Homebrew: -Installing it is very easy through Homebrew: +``` +brew install postgresql +``` - $ brew update - $ brew install mongo +It will automatically add itself to Homebrew Services. Start it with: -### Usage - -In a terminal, start the MongoDB server: +``` +brew services start postgresql +``` - $ mongod +If you reboot your machine, PostgreSQL will be restarted at login. -In another terminal, connect to the database with the Mongo shell using: +### GUI - $ mongo +You can interact with your SQL database by running `psql` in the terminal. -I'll let you refer to MongoDB's [Getting Started](http://docs.mongodb.org/manual/tutorial/getting-started/) guide for more! +If you prefer a GUI (Graphical User Interface), [Postico](https://eggerapps.at/postico/) has a simple free version that let's you explore tables and run SQL queries. ## Redis -[Redis](http://redis.io/) 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](http://oldblog.antirez.com/post/take-advantage-of-redis-adding-it-to-your-stack.html) 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. - -### Install +[Redis](http://redis.io/) is a fast, in-memory, key-value store, that uses the disk for persistence. It complements nicely a database such as PostgreSQL. There are a lot of [interesting things](http://oldblog.antirez.com/post/take-advantage-of-redis-adding-it-to-your-stack.html) that you can do with it. For example, it's often used for session management or caching by web apps, but it has many other uses. To install Redis, use Homebrew: - $ brew update - $ brew install redis - -### Usage - -Start a local Redis server using the default configuration settings with: - - $ redis-server - -For advanced usage, you can tweak the configuration file at `/usr/local/etc/redis.conf` (I suggest making a backup first), and use those settings with: - - $ redis-server /usr/local/etc/redis.conf +``` +brew install redis +``` -In another terminal, connect to the server with the Redis command-line interface using: +Start it through Homebrew Services with: - $ redis-cli +``` +brew services start redis +``` I'll let you refer to Redis' [documentation](http://redis.io/documentation) or other tutorials for more information. ## Elasticsearch -As it says on the box, [Elasticsearch](http://www.elasticsearch.org/) 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. +[Elasticsearch](https://www.elastic.co/products/elasticsearch) is a distributed search and analytics engine. It uses an HTTP REST API, making it 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. +You can use elasticsearch for things such as real-time search results, autocomplete, recommendations, machine learning, and more. ### Install @@ -794,64 +803,52 @@ Elasticsearch runs on Java, so check if you have it installed by running: java -version ``` -If Java isn't installed yet, a window will appear prompting you to install it. Go ahead and click "Install". +If Java isn't installed yet, dismiss the window that just appeared by clicking "Ok", and install Java via Homebrew: -Next, install elasticsearch with: - -```bash -$ brew install elasticsearch ``` - -**Note**: 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): - -```bash -$ mv /usr/local/bin/plugin /usr/local/bin/elasticsearch-plugin +brew cask install homebrew/cask-versions/java8 ``` -Below 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](http://mobz.github.io/elasticsearch-head/), which gives you a web interface to the REST API. Install it with: +Next, install Elasticsearch with: ```bash -$ elasticsearch-plugin --install mobz/elasticsearch-head +brew install elasticsearch ``` ### Usage -Start a local elasticsearch server with: +Start the Elasticsearch server with: ```bash -$ elasticsearch -f +brew services start elasticsearch ``` -(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: ```bash -$ curl -XGET 'http://localhost:9200/' +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](http://www.elasticsearch.org/guide/) is more of a reference. To get started, I suggest reading some of the blog posts linked on this [StackOverflow answer](http://stackoverflow.com/questions/11593035/beginners-guide-to-elasticsearch/11767610#11767610). +(You may need to wait a little bit for it to boot up if you just started the service.) -## Projects folder +Elasticsearch's [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html) is more of a reference. To get started, you can also take a look at [Elasticsearch: The Definitive Guide](https://www.elastic.co/guide/en/elasticsearch/guide/master/index.html). -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`. +### GUI -## Apps +You can interact with the Elasticsearch server using `curl`, or anything that can send an HTTP request. -Here is a quick list of some apps I use, and that you might find useful as well: +However, if you prefer a graphical interface, you can take a look at [Dejavu](https://opensource.appbase.io/dejavu/). You can easily install it via the [Dejavu Chrome Extension](https://chrome.google.com/webstore/detail/dejavu-elasticsearch-web/jopjeaiilkcibeohjdmejhoifenbnmlh). -- [Dropbox](https://www.dropbox.com/): 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](https://drive.google.com/): 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](https://agilebits.com/onepassword): 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](http://markedapp.com/): As a developer, most of the stuff you write ends up being in [Markdown](http://daringfireball.net/projects/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. **($4)** -- [Path Finder](http://cocoatech.com/pathfinder/): I love OSX, it's Unix so great for developers, and all of it just works and looks pretty! Only thing I "miss" from Windows (OMG what did he say?), is a decent file explorer. I think Finder is a pain to use. So I gladly paid for this alternative, but I understand others might find it expensive just to not have to use Finder. **($40)** -- [Evernote](https://evernote.com/): 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](http://simplenote.com/) 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)** -- [Moom](http://manytricks.com/moom/): Don't waste time resizing and moving your windows. Moom makes this very easy. **($10)** +## Projects folder +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](https://www.dropbox.com/) installed), or `~/Documents` if you prefer to use [iCloud Drive](https://support.apple.com/en-ca/HT206985). +## Apps +Here is a quick list of some apps I use, and that you might find useful as well: +- [1Password](https://1password.com/): Securely store your login and passwords, and access them from all your devices. **($3/month)** +- [Dropbox](https://www.dropbox.com/): File syncing to the cloud. It is cross-platform, but if all your devices are Apple you may prefer [iCloud Drive](https://support.apple.com/en-ca/HT206985). **(Free for 2GB)** +- [Postman](https://www.getpostman.com/): Easily make HTTP requests. Useful to test your REST APIs. **(Free for basic features)** +- [GitHub Desktop](https://desktop.github.com/): I do everything through the `git` command-line tool, but I like to use GitHub Desktop just to review the diff of my changes. **(Free)** +- [Spectacle](https://www.spectacleapp.com/): Move and resize windows with keyboard shortcuts. **(Free)**