How I setup my Mac for development.
Tags: beginners, ruby, node, webdev
Published: 2019-06-03 09:02:03

---
title: How I setup my Mac for development.
published: true
description:
tags: beginners,ruby,nodejs,webdev
---

Every time I get a new Mac or upgrading MacOS, the pain is reinstalling everything.

I had to take notes on what must be done, and google a bunch of stuffs.

So I decided to write this blog for my personal use and hope that it's useful for other people.

There maybe things that you see that I can improve my dev environment. Please comment so I can be a better developer.

> NOTE: I just got a new Mac Mini 2018 i5 SSD256GB RAM20GB and I'm on Mojave OS

# Check / Set my home folder

I sometime see people use long username in home folder. I usually go with short and easy to remember username. Mine is `sakko`.

To check, type open terminal and type `pwd`

```bash
$ pwd
/Users/sakko
```

If it's not what you like, find a way to change it now before continuing. It will be extremely difficult to change this after a few months.

# Install Xcode

Download Xcode from here https://developer.apple.com/download/more/ or the Apple App Store.

Then try creating a single page app iOS project. Run the project to see if it build successfully.

# Install Xcode Command Line Tools

Open terminal and type

```bash
$ xcode-select --install
```

Then click `install` to continue

# Configure git config

Open terminal and input these (replace your name and email)

```bash
$ git config --global user.name "John Doe"
$ git config --global user.email "john.doe@gmail.com"

```

# Setup global .gitignores

Mac has some annoying files that can be ignored by git. Let's add them.

```bash
$ nano ~/.gitignore
```

Then add these

```
# Node
npm-debug.log

# Mac
.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows
Thumbs.db

# WebStorm
.idea/
```

After you are done, activate this globally by running

```bash
$ git config --global core.excludesfile ~/.gitignore
```

# Install NVM

For nodejs development, open https://github.com/nvm-sh/nvm

copy the installation line (eg.)

```bash
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
```

Open `~/.bash_profile` and add `source ~/.bashrc` to the first line.

Open `~/.bashrc` and see if these lines are present. (if not, add it)

```
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
```

If you are using `.nvmrc` in your projects to activate node version like `.ruby-version`, then also add these into your `.bashrc`

```
enter_directory() {
if [[ $PWD == $PREV_PWD ]]; then
    return
fi

PREV_PWD=$PWD
if [[ -f ".nvmrc" ]]; then
    nvm use
    NVM_DIRTY=true
elif [[ $NVM_DIRTY = true ]]; then
    nvm use default
    NVM_DIRTY=false
fi
}

export PROMPT_COMMAND=enter_directory
```

Then install nodejs (only the version you use)

```bash
$ nvm install 10.16.0
$ nvm install node    # this will install latest
```

# Install Ruby

I'm a Rails developer so I need ruby as well. I choose rvm (like nvm) to manage versions and gemsets.

Simply run the command below and follow what's prompted.

```bash
$ \curl -sSL https://get.rvm.io | bash -s stable

```

> When it's done, restart terminal once, to get rvm loaded.

Install ruby, I use `2.5.3` and `2.6.3` at the moment

```bash
$ rvm install 2.5.3
$ rvm install 2.6.3
```

I don't like document to be installed (to save space) so I usually globally ignore it. (Not sure if this is necessary anymore)

```bash
$ echo "gem: --no-document" >> ~/.gemrc
```

Then install latest version of Rails

```bash
$ gem install rails
```

# Homebrew, Postgresql, MySql, ElasticSearch, Redis and other apps

RVM will install Homebrew for you, so you don't need to reinstall it.

So let's install other apps

```bash
# image processing
$ brew install imagemagick gs vips

# postgresql
$ brew install postgresql
$ brew services start postgresql # to start service

# mysql
$ brew install mysql
$ brew services start mysql # to start service

# redis
$ brew install redis
$ brew services start redis # to start service

# memcached
$ brew install memcached
$ brew services start memcached # to start service
```

Installing ElasticSearch require Java8 you can download them from here.

- https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html

Agree with the terms or use openjdk from Homebrew

```bash
$ brew tap AdoptOpenJDK/openjdk
$ brew cask install adoptopenjdk8
```

Then install ElasticSearch

```bash
# elasticsearch
$ brew install elasticsearch
$ brew services start elasticsearch # to start service
```

# Android development + React-Native

The best tutorial is the official one.

https://facebook.github.io/react-native/docs/getting-started

# Other Apps I use

- Atom.io
- VSCode
- Sublime
- iTerm2
- Alfred
- 1Password
- Little Snitch
- iStat Menus

# Atom packages

I usually start with these packages, (you need to `install shell command` from atom application menu first)

```bash
apm install atom-beautify blame console-log editorconfig emmet es6-javascript language-docker language-javascript-jsx language-plantuml language-vue linter linter-swagger linter-ui-default plantuml-preview prettier-atom rails-snippets react react-es6-snippets ruby-block set-syntax
```

# Sublime

I usually use Sublime if I want to quickly open some file (especially JSON). Since it's the fastest editor I can find with all the features I need. These are the packages I usually use.

```
Babel
Emmet
GitGutter
JsPrettier
JSX
```

# Other stuffs,

Docker - not yet, I'm saving my precious 256GB ssd T____T

python, gcloud, ansible, blah blah blah..... too many to add. Install them later.

Anything I should add?