├── .gitignore ├── .bash_profile ├── .gitconfig ├── .aliases ├── .bash_prompt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Folder view configuration files 2 | .DS_Store 3 | Desktop.ini 4 | 5 | # Thumbnail cache files 6 | ._* 7 | Thumbs.db 8 | 9 | # Files that might appear on external disks 10 | .Spotlight-V100 11 | .Trashes 12 | -------------------------------------------------------------------------------- /.bash_profile: -------------------------------------------------------------------------------- 1 | # Add `~/bin` to the `$PATH` 2 | export PATH="$HOME/bin:$PATH"; 3 | 4 | # Load the shell dotfiles, and then some: 5 | # * ~/.path can be used to extend `$PATH`. 6 | # * ~/.extra can be used for other settings you don’t want to commit. 7 | for file in ~/.{path,bash_prompt,exports,aliases,functions,extra}; do 8 | [ -r "$file" ] && [ -f "$file" ] && source "$file"; 9 | done; 10 | unset file; 11 | -------------------------------------------------------------------------------- /.gitconfig: -------------------------------------------------------------------------------- 1 | [alias] 2 | # Show verbose output about tags, branches or remotes 3 | tags = tag -l 4 | branches = branch -a 5 | remotes = remote -v 6 | # Pretty log output 7 | hist = log --graph --pretty=format:'%Cred%h%Creset %s%C(yellow)%d%Creset %Cgreen(%cr)%Creset [%an]' --abbrev-commit --date=relative 8 | 9 | [color] 10 | # Use colors in Git commands that are capable of colored output when 11 | # outputting to the terminal. (This is the default setting in Git ≥ 1.8.4.) 12 | ui = auto 13 | [color "branch"] 14 | current = yellow reverse 15 | local = yellow 16 | remote = green 17 | [color "diff"] 18 | meta = yellow bold 19 | frag = magenta bold 20 | old = red bold 21 | new = green bold 22 | [color "status"] 23 | added = yellow 24 | changed = green 25 | untracked = cyan 26 | -------------------------------------------------------------------------------- /.aliases: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Detect which `ls` flavor is in use 4 | if ls --color > /dev/null 2>&1; then # GNU `ls` 5 | colorflag="--color" 6 | else # macOS `ls` 7 | colorflag="-G" 8 | fi 9 | 10 | # List all files colorized in long format 11 | alias ll="ls -lF ${colorflag}" 12 | 13 | # List all files colorized in long format, including dot files 14 | alias la="ls -laF ${colorflag}" 15 | 16 | # List only directories 17 | alias lsd="ls -lF ${colorflag} | grep --color=never '^d'" 18 | 19 | # Always use color output for `ls` 20 | alias ls="command ls ${colorflag}" 21 | export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:' 22 | -------------------------------------------------------------------------------- /.bash_prompt: -------------------------------------------------------------------------------- 1 | # @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt” 2 | # Shamelessly copied from https://github.com/gf3/dotfiles 3 | 4 | if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then 5 | export TERM='gnome-256color'; 6 | elif infocmp xterm-256color >/dev/null 2>&1; then 7 | export TERM='xterm-256color'; 8 | fi; 9 | 10 | if tput setaf 1 &> /dev/null; then 11 | tput sgr0; # reset colors 12 | bold=$(tput bold); 13 | reset=$(tput sgr0); 14 | # Oceanic Next colors 15 | black=$(tput setaf 16); 16 | blue=$(tput setaf 68); 17 | cyan=$(tput setaf 73); 18 | green=$(tput setaf 114); 19 | orange=$(tput setaf 209); 20 | magenta=$(tput setaf 176); 21 | red=$(tput setaf 203); 22 | white=$(tput setaf 66); 23 | yellow=$(tput setaf 221); 24 | else 25 | bold=''; 26 | reset="\e[0m"; 27 | black="\e[1;30m"; 28 | blue="\e[1;34m"; 29 | cyan="\e[1;36m"; 30 | green="\e[1;32m"; 31 | orange="\e[1;33m"; 32 | magenta="\e[1;35m"; 33 | red="\e[1;31m"; 34 | white="\e[1;37m"; 35 | yellow="\e[1;33m"; 36 | fi; 37 | 38 | function parse_git_dirty() { 39 | [[ $(git status 2> /dev/null | tail -n1) != *"nothing to commit"* ]] && echo "*" 40 | } 41 | 42 | function parse_git_branch() { 43 | git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" 44 | } 45 | 46 | PS1="\[${bold}\]\[$green\]\w\[$white\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$magenta\]\$(parse_git_branch)\[$white\]\n\$ \[$reset\]" 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # macOS Dev Setup 2 | 3 | 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. 4 | 5 | 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. 6 | 7 | **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! 8 | 9 | - [System update](#system-update) 10 | - [System preferences](#system-preferences) 11 | - [Security](#security) 12 | - [iTerm2](#iterm2) 13 | - [Homebrew](#homebrew) 14 | - [Git](#git) 15 | - [Visual Studio Code](#visual-studio-code) 16 | - [Vim](#vim) 17 | - [Python](#python) 18 | - [Node.js](#nodejs) 19 | - [Ruby](#ruby) 20 | - [Heroku](#heroku) 21 | - [PostgreSQL](#postgresql) 22 | - [Redis](#redis) 23 | - [Elasticsearch](#elasticsearch) 24 | - [Projects folder](#projects-folder) 25 | - [Apps](#apps) 26 | 27 | ## System update 28 | 29 | First thing you need to do, on any OS actually, is update the system! For that: **Apple Icon > About This Mac** then **Software Update...**. 30 | 31 | ## System preferences 32 | 33 | 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. 34 | 35 | In **Apple Icon > System Preferences**: 36 | 37 | - Trackpad > Tap to click 38 | - Keyboard > Key Repeat > Fast (all the way to the right) 39 | - Keyboard > Delay Until Repeat > Short (all the way to the right) 40 | - Dock > Automatically hide and show the Dock 41 | 42 | ## Security 43 | 44 | 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. 45 | 46 | In **Apple Icon > System Preferences**: 47 | 48 | - Users & Groups: If you haven't already set a password for your user during the initial set up, you should do so now 49 | - 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) 50 | - Security & Privacy > FileVault: Make sure FileVault disk encryption is enabled 51 | - iCloud: If you haven't already done so during set up, enable Find My Mac 52 | 53 | ## iTerm2 54 | 55 | ### Install 56 | 57 | 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/). 58 | 59 | In **Finder**, drag and drop the **iTerm** Application file into the **Applications** folder. 60 | 61 | You can now launch iTerm, through the **Launchpad** for instance. 62 | 63 | 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**. 64 | 65 | 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**. 66 | 67 | 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. 68 | 69 | ### Beautiful terminal 70 | 71 | 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. 72 | 73 | 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: 74 | 75 | ``` 76 | cd ~/Downloads 77 | curl -o "Atom One Dark.itermcolors" https://raw.githubusercontent.com/nathanbuchar/atom-one-dark-terminal/master/scheme/iterm/One%20Dark.itermcolors 78 | curl -o "Atom One Light.itermcolors" https://raw.githubusercontent.com/nathanbuchar/atom-one-dark-terminal/master/scheme/iterm/One%20Light.itermcolors 79 | ``` 80 | 81 | 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). 82 | 83 | 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). 84 | 85 | 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): 86 | 87 | ``` 88 | cd ~ 89 | curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_profile 90 | curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.bash_prompt 91 | curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.aliases 92 | ``` 93 | 94 | 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`). 95 | 96 | Now we have a terminal we can work with! 97 | 98 | (Thanks to Mathias Bynens for his awesome [dotfiles](https://github.com/mathiasbynens/dotfiles).) 99 | 100 | ## Homebrew 101 | 102 | 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/). 103 | 104 | ### Install 105 | 106 | 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: 107 | 108 | ``` 109 | xcode-select --install 110 | ``` 111 | 112 | Once that is done, we can install Homebrew by copy-pasting the installation command from the [Homebrew homepage](http://brew.sh/) inside the terminal: 113 | 114 | ``` 115 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 116 | ``` 117 | 118 | Follow the steps on the screen. You will be prompted for your user password so Homebrew can set up the appropriate permissions. 119 | 120 | Once installation is complete, you can run the following command to make sure everything works: 121 | 122 | ``` 123 | brew doctor 124 | ``` 125 | 126 | ### Usage 127 | 128 | To install a package (or **Formula** in Homebrew vocabulary) simply type: 129 | 130 | ``` 131 | brew install 132 | ``` 133 | 134 | To see if any of your packages need to be updated: 135 | 136 | ``` 137 | brew outdated 138 | ``` 139 | 140 | To update a package: 141 | 142 | ``` 143 | brew upgrade 144 | ``` 145 | 146 | 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: 147 | 148 | ``` 149 | brew cleanup 150 | ``` 151 | 152 | To see what you have installed (with their version numbers): 153 | 154 | ``` 155 | brew list --versions 156 | ``` 157 | 158 | ### Homebrew Services 159 | 160 | 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. 161 | 162 | Homebrew Services will automatically install itself the first time you run it, so there is nothing special to do. 163 | 164 | After installing a service (for example a database), it should automatically add itself to Homebrew Services. If not, you can add it manually with: 165 | 166 | ``` 167 | brew services 168 | ``` 169 | 170 | Start a service with: 171 | 172 | ``` 173 | brew services start 174 | ``` 175 | 176 | At anytime you can view which services are running with: 177 | 178 | ``` 179 | brew services list 180 | ``` 181 | 182 | ## Git 183 | 184 | 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: 185 | 186 | ``` 187 | brew install git 188 | ``` 189 | 190 | When done, to test that it installed fine you can run: 191 | 192 | ``` 193 | which git 194 | ``` 195 | 196 | The output should be `/usr/local/bin/git`. 197 | 198 | 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: 199 | 200 | ``` 201 | cd ~ 202 | curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.gitconfig 203 | ``` 204 | 205 | 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. 206 | 207 | 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/)): 208 | 209 | ``` 210 | git config --global user.name "Your Name Here" 211 | git config --global user.email "your_email@youremail.com" 212 | ``` 213 | 214 | They will get added to your `.gitconfig` file. 215 | 216 | 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): 217 | 218 | ``` 219 | cd ~ 220 | curl -O https://raw.githubusercontent.com/nicolashery/mac-dev-setup/master/.gitignore 221 | git config --global core.excludesfile ~/.gitignore 222 | ``` 223 | 224 | ## Visual Studio Code 225 | 226 | 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. 227 | 228 | 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. 229 | 230 | **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**. 231 | 232 | 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: 233 | 234 | ```json 235 | { 236 | "editor.tabSize": 2, 237 | "editor.rulers": [80], 238 | "files.insertFinalNewline": true, 239 | "files.trimTrailingWhitespace": true, 240 | "workbench.editor.enablePreview": false 241 | } 242 | ``` 243 | 244 | Feel free to tweak these to your preference. When done, save the file and close it. 245 | 246 | 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. 247 | 248 | 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. 249 | 250 | 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: 251 | 252 | ``` 253 | cd myproject/ 254 | code . 255 | ``` 256 | 257 | VS Code is very extensible. To customize it further, open the **Extensions** tab on the left. 258 | 259 | 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). 260 | 261 | 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). 262 | 263 | ## Vim 264 | 265 | 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. 266 | 267 | For example, when you run a Git commit, it will open Vim to allow you to type the commit message. 268 | 269 | 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. 270 | 271 | 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. 272 | 273 | Using Vim's built-in package support, install these settings by running: 274 | 275 | ``` 276 | mkdir -p ~/.vim/pack/tpope/start 277 | cd ~/.vim/pack/tpope/start 278 | git clone https://tpope.io/vim/sensible.git 279 | ``` 280 | 281 | With that, Vim will look a lot better next time you open it! 282 | 283 | ## Python 284 | 285 | 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. 286 | 287 | Install `pyenv` via Homebrew by running: 288 | 289 | ``` 290 | brew install pyenv 291 | ``` 292 | 293 | 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: 294 | 295 | ```bash 296 | if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)"; fi 297 | ``` 298 | 299 | Save the file and reload it with: 300 | 301 | ``` 302 | source ~/.bash_profile 303 | ``` 304 | 305 | Before installing a new Python version, the [pyenv wiki](https://github.com/pyenv/pyenv/wiki) recommends having a few dependencies available: 306 | 307 | ``` 308 | brew install openssl readline sqlite3 xz zlib 309 | ``` 310 | 311 | We can now list all available Python versions by running: 312 | 313 | ``` 314 | pyenv install --list 315 | ``` 316 | 317 | Look for the latest 3.x version (or 2.7.x), and install it (replace the `.x.x` with actual numbers): 318 | 319 | ``` 320 | pyenv install 3.x.x 321 | ``` 322 | 323 | List the Python versions you have locally with: 324 | 325 | ``` 326 | pyenv versions 327 | ``` 328 | 329 | 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. 330 | 331 | You can switch your current terminal to another Python version with: 332 | 333 | ``` 334 | pyenv shell 3.x.x 335 | ``` 336 | 337 | You should now see that version when running: 338 | 339 | ``` 340 | python --version 341 | ``` 342 | 343 | In a project directory, you can use: 344 | 345 | ``` 346 | pyenv local 3.x.x 347 | ``` 348 | 349 | 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. 350 | 351 | For more information, see the [pyenv commands](https://github.com/yyuu/pyenv/blob/master/COMMANDS.md) documentation. 352 | 353 | ### pip 354 | 355 | [pip](https://pip.pypa.io) was also installed by `pyenv`. It is the package manager for Python. 356 | 357 | Here are a couple Pip commands to get you started. To install a Python package: 358 | 359 | ``` 360 | pip install 361 | ``` 362 | 363 | To upgrade a package: 364 | 365 | ``` 366 | pip install --upgrade 367 | ``` 368 | 369 | To see what's installed: 370 | 371 | ``` 372 | pip freeze 373 | ``` 374 | 375 | To uninstall a package: 376 | 377 | ``` 378 | pip uninstall 379 | ``` 380 | 381 | ### virtualenv 382 | 383 | [virtualenv](https://virtualenv.pypa.io) is a tool that creates an isolated Python environment for each of your projects. 384 | 385 | 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. 386 | 387 | 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: 388 | 389 | ``` 390 | brew install pyenv-virtualenv 391 | ``` 392 | 393 | After installation, add the following line to your `.bash_profile`: 394 | 395 | ```bash 396 | if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi 397 | ``` 398 | 399 | And reload it with: 400 | 401 | ``` 402 | source ~/.bash_profile 403 | ``` 404 | 405 | 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): 406 | 407 | ``` 408 | pyenv virtualenv 3.x.x myproject 409 | ``` 410 | 411 | See the list of virtualenvs you created with: 412 | 413 | ``` 414 | pyenv virtualenvs 415 | ``` 416 | 417 | To use your project's virtualenv, you need to **activate** it first (in every terminal where you are working on your project): 418 | 419 | ``` 420 | pyenv activate myproject 421 | ``` 422 | 423 | If you run `pyenv virtualenvs` again, you should see a star (`*`) next to the active virtualenv. 424 | 425 | Now when you install something: 426 | 427 | ``` 428 | pip install 429 | ``` 430 | 431 | It will get installed in that virtualenv's folder, and not conflict with other projects. 432 | 433 | You can also set your project's `.python-version` to point to a virtualenv you created: 434 | 435 | ``` 436 | pyenv local myproject 437 | ``` 438 | 439 | Next time you enter that project's directory, `pyenv` will automatically load the virtualenv for you. 440 | 441 | ### Anaconda and Miniconda 442 | 443 | The Anaconda/Miniconda distributions of Python come with many useful tools for scientific computing. 444 | 445 | You can install them using `pyenv`, for example (replace `x.x.x` with an actual version number): 446 | 447 | ``` 448 | pyenv install miniconda3-x.x.x 449 | ``` 450 | 451 | 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): 452 | 453 | ``` 454 | pyenv shell miniconda3-x.x.x 455 | conda create --name mycondaproject 456 | conda activate mycondaproject 457 | ``` 458 | 459 | Install packages, for example the [Jupyter Notebook](https://jupyter.org/), using: 460 | 461 | ``` 462 | conda install jupyter 463 | ``` 464 | 465 | You should now be able to run the notebook: 466 | 467 | ``` 468 | jupyter notebook 469 | ``` 470 | 471 | Deactivate the environment, and return to the default Python version with: 472 | 473 | ``` 474 | conda deactivate 475 | pyenv shell --unset 476 | ``` 477 | 478 | ### Known issue: `gettext` not found by `git` after installing Anaconda/Miniconda 479 | 480 | If you installed an Anaconda/Miniconda distribution, you may start seeing an error message when using certain `git` commands, similar to this one: 481 | 482 | ``` 483 | pyenv: gettext.sh: command not found 484 | 485 | The `gettext.sh' command exists in these Python versions: 486 | miniconda3-latest 487 | ``` 488 | 489 | If that is the case, you can use the following [workaround](https://github.com/pyenv/pyenv/issues/688#issuecomment-428675578): 490 | 491 | ``` 492 | brew install gettext 493 | ``` 494 | 495 | Then add this line to your `.bash_profile`: 496 | 497 | ```bash 498 | # Workaround for: https://github.com/pyenv/pyenv/issues/688#issuecomment-428675578 499 | export PATH="/usr/local/opt/gettext/bin:$PATH" 500 | ``` 501 | 502 | ## Node.js 503 | 504 | 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. 505 | 506 | Install `nvm` by copy-pasting the [install script command](https://github.com/creationix/nvm#install--update-script) into your terminal. 507 | 508 | Once that is done, open a new terminal and verify that it was installed correctly by running: 509 | 510 | ``` 511 | command -v nvm 512 | ``` 513 | 514 | View the all available stable versions of Node with: 515 | 516 | ``` 517 | nvm ls-remote --lts 518 | ``` 519 | 520 | Install the latest stable version with: 521 | 522 | ``` 523 | nvm install node 524 | ``` 525 | 526 | It will also set the first version installed as your default version. You can install another specific version, for example Node 10, with: 527 | 528 | ``` 529 | nvm install 10 530 | ``` 531 | 532 | And switch between versions by using: 533 | 534 | ``` 535 | nvm use 10 536 | nvm use default 537 | ``` 538 | 539 | See which versions you have install with: 540 | 541 | ``` 542 | nvm ls 543 | ``` 544 | 545 | Change the default version with: 546 | 547 | ``` 548 | nvm alias default 10 549 | ``` 550 | 551 | In a project's directory you can create a `.nvmrc` file containing the Node.js version the project uses, for example: 552 | 553 | ``` 554 | echo "10" > .nvmrc 555 | ``` 556 | 557 | Next time you enter the project's directory from a terminal, you can load the correct version of Node.js by running: 558 | 559 | ``` 560 | nvm use 561 | ``` 562 | 563 | ### npm 564 | 565 | Installing Node also installs the [npm](https://npmjs.org/) package manager. 566 | 567 | To install a package: 568 | 569 | ``` 570 | npm install # Install locally 571 | npm install -g # Install globally 572 | ``` 573 | 574 | To install a package and save it in your project's `package.json` file: 575 | 576 | ``` 577 | npm install --save 578 | ``` 579 | 580 | To see what's installed: 581 | 582 | ``` 583 | npm list --depth 1 # Local packages 584 | npm list -g --depth 1 # Global packages 585 | ``` 586 | 587 | To find outdated packages (locally or globally): 588 | 589 | ``` 590 | npm outdated [-g] 591 | ``` 592 | 593 | To upgrade all or a particular package: 594 | 595 | ``` 596 | npm update [] 597 | ``` 598 | 599 | To uninstall a package: 600 | 601 | ``` 602 | npm uninstall --save 603 | ``` 604 | 605 | ## Ruby 606 | 607 | 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. 608 | 609 | ### Install 610 | 611 | 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: 612 | 613 | ``` 614 | brew install rbenv 615 | ``` 616 | 617 | After installation, add the following line to your `.bash_profile`: 618 | 619 | ```bash 620 | eval "$(rbenv init -)" 621 | ``` 622 | 623 | And reload it with: 624 | 625 | ``` 626 | source ~/.bash_profile 627 | ``` 628 | 629 | ### Usage 630 | 631 | The following command will show you which versions of Ruby are available to install: 632 | 633 | ``` 634 | rbenv install --list 635 | ``` 636 | 637 | You can find the latest version in that list and install it with (replace `.x.x` with actual version numbers): 638 | 639 | ``` 640 | rbenv install 2.x.x 641 | ``` 642 | 643 | Run the following to see which versions you have installed: 644 | 645 | ``` 646 | rbenv versions 647 | ``` 648 | 649 | 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: 650 | 651 | ``` 652 | rbenv shell 2.x.x 653 | ``` 654 | 655 | You can also set it as the default version if you want: 656 | 657 | ``` 658 | rbenv global 2.x.x 659 | ``` 660 | 661 | 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: 662 | 663 | ``` 664 | rbenv local 2.x.x 665 | ``` 666 | 667 | Check anytime which version you are using with: 668 | 669 | ``` 670 | rbenv version 671 | ``` 672 | 673 | See [rbenv's command reference](https://github.com/rbenv/rbenv#command-reference) for more information. 674 | 675 | ### RubyGems & Bundler 676 | 677 | [RubyGems](http://rubygems.org/), the Ruby package manager, was also installed: 678 | 679 | ``` 680 | which gem 681 | ``` 682 | 683 | 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: 684 | 685 | ``` 686 | gem install bundler 687 | ``` 688 | 689 | In a new Ruby project directory, create a new `Gemfile` with: 690 | 691 | ``` 692 | bundle init 693 | ``` 694 | 695 | Add a dependency to the `Gemfile`, for example the [Jekyll]() static site generator: 696 | 697 | ```ruby 698 | source "https://rubygems.org" 699 | 700 | gem "jekyll" 701 | ``` 702 | 703 | Then install the project's dependencies with: 704 | 705 | ``` 706 | bundle install 707 | ``` 708 | 709 | Make sure you check in both the `Gemfile` and `Gemfile.lock` into your Git repository. 710 | 711 | Update a specific dependency with: 712 | 713 | ``` 714 | bundle update 715 | ``` 716 | 717 | For more information, see the [Bundler documentation](https://bundler.io/docs.html). 718 | 719 | ## Heroku 720 | 721 | [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/). 722 | 723 | 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): 724 | 725 | ``` 726 | brew tap heroku/brew 727 | brew install heroku 728 | ``` 729 | 730 | Login to your Heroku account using: 731 | 732 | ``` 733 | heroku login 734 | ``` 735 | 736 | (This will prompt you to open a page in your web browser and log in to your Heroku account.) 737 | 738 | 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): 739 | 740 | ``` 741 | cd myapp/ 742 | heroku create myapp 743 | git push heroku master 744 | heroku ps 745 | heroku logs -t 746 | ``` 747 | 748 | The [Heroku Dev Center](https://devcenter.heroku.com/) is full of great resources, so be sure to check it out! 749 | 750 | ## PostgreSQL 751 | 752 | [PostgreSQL](https://www.postgresql.org/) is a popular relational database, and Heroku has first-class support for it. 753 | 754 | Install PostgreSQL using Homebrew: 755 | 756 | ``` 757 | brew install postgresql 758 | ``` 759 | 760 | It will automatically add itself to Homebrew Services. Start it with: 761 | 762 | ``` 763 | brew services start postgresql 764 | ``` 765 | 766 | If you reboot your machine, PostgreSQL will be restarted at login. 767 | 768 | ### GUI 769 | 770 | You can interact with your SQL database by running `psql` in the terminal. 771 | 772 | 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. 773 | 774 | ## Redis 775 | 776 | [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. 777 | 778 | To install Redis, use Homebrew: 779 | 780 | ``` 781 | brew install redis 782 | ``` 783 | 784 | Start it through Homebrew Services with: 785 | 786 | ``` 787 | brew services start redis 788 | ``` 789 | 790 | I'll let you refer to Redis' [documentation](http://redis.io/documentation) or other tutorials for more information. 791 | 792 | ## Elasticsearch 793 | 794 | [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. 795 | 796 | You can use elasticsearch for things such as real-time search results, autocomplete, recommendations, machine learning, and more. 797 | 798 | ### Install 799 | 800 | Elasticsearch runs on Java, so check if you have it installed by running: 801 | 802 | ```bash 803 | java -version 804 | ``` 805 | 806 | If Java isn't installed yet, dismiss the window that just appeared by clicking "Ok", and install Java via Homebrew: 807 | 808 | ``` 809 | brew cask install homebrew/cask-versions/java8 810 | ``` 811 | 812 | Next, install Elasticsearch with: 813 | 814 | ```bash 815 | brew install elasticsearch 816 | ``` 817 | 818 | ### Usage 819 | 820 | Start the Elasticsearch server with: 821 | 822 | ```bash 823 | brew services start elasticsearch 824 | ``` 825 | 826 | Test that the server is working correctly by running: 827 | 828 | ```bash 829 | curl -XGET 'http://localhost:9200/' 830 | ``` 831 | 832 | (You may need to wait a little bit for it to boot up if you just started the service.) 833 | 834 | 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). 835 | 836 | ### GUI 837 | 838 | You can interact with the Elasticsearch server using `curl`, or anything that can send an HTTP request. 839 | 840 | 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). 841 | 842 | ## Projects folder 843 | 844 | 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). 845 | 846 | ## Apps 847 | 848 | Here is a quick list of some apps I use, and that you might find useful as well: 849 | 850 | - [1Password](https://1password.com/): Securely store your login and passwords, and access them from all your devices. **($3/month)** 851 | - [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)** 852 | - [Postman](https://www.getpostman.com/): Easily make HTTP requests. Useful to test your REST APIs. **(Free for basic features)** 853 | - [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)** 854 | - [Spectacle](https://www.spectacleapp.com/): Move and resize windows with keyboard shortcuts. **(Free)** 855 | --------------------------------------------------------------------------------