How to setup Mac for development in 2024. (Ruby on Rails and NodeJS)
Tags: mac, ruby, rails, node
Published: 2024-05-29 06:45:55

---
title: How to setup Mac for development in 2024. (Ruby on Rails and NodeJS)
published: true
description: Setup mac on Sonoma 14.x.x. xcode, homebrew, ruby, rvm, nodejs, nvm, docker, postgres, sublime, etc.
tags: mac,ruby,rails,nodejs
---

It's been awhile ([Since my previous post](https://dev.to/sakko/how-i-upgrade-my-mac-for-development-in-catalina-macos-33g1)) and the new members in my teams are having difficulties setting up their new laptop. (Especially if they are previously Windows user)

So let's begin, 

# The good username (Account name)

If you happen to read this before you first setup your mac, you should try to setup your username to be `lowercase with no space`.

![The good username](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltjcit2gz7mkdn50tgyq.png)

This is because there will be time you want to access the path directly and your don't want to mistyped `/Users/sakko` vs `/Users/SaKKo`. (This path will be your `~` or $HOME directory) By simplifying the username, it might save you a lot of time since in Ubuntu they setup the username as `/home/ubuntu` as well.

# XCode or Just CLI 

Every mac is nearly ready for software development. The easiest way to get start is to just install Xcode from App Store.

[![Xcode](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wlw3qy0s4pjv2b69e8po.png)](https://developer.apple.com/xcode/)

If you are like me, you only want to install what you are using. So, unless you are immediately writing iOS application, then don't install xcode just yet. Instead press `⌘+space` and type terminal. 

![Open Terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3i7602y6ijo1yrnjexd1.png)

And just run this command in terminal. 

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

![xcode-select --install](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/payw9cl0vzr192lknqsr.png)

There should be a popup. Click install and then complete the installation processes.

![xcode-select --install popup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8nw6gh40poztne8jbob.png)

When it's done, you should restart the terminal session. The easiest way is to click at the current terminal window and press `⌘+w` to close current tab. Then press `⌘+t` to start a new tab. Also note that this shortcut is usable in other apps as well.

# Homebrew

I know some might disagree, but Homebrew is a real time-saver for me. Here is the link for you to get start (or just keep reading)

[![Homebrew website](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrub7uw68g9b24wuqujm.png)](https://brew.sh/)

Simply run this command in terminal

```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r28tvbt3eiy3vu48dxg1.png)

There are 3 steps here

1. paste the command
2. type your password (you can't see it, just type and press enter)
3. Just press enter to confirm installation path. (Don't input anything else) You don't want to mess with this path.

When everything stop, many people will think that it's done. But it's not, you must copy the command in the `Next steps:` section and run it in terminal. NOTE: Copy both lines, don't miss any.

![After Homebrew finish installing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7kyvhr3mdih4mz6ob0qv.png)

If you missed it, here is the command. ($HOME is your home directory)

```bash
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> $HOME/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
```

![Run Homebrew zprofile script](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pd3ro63lvc4ajqiud8hh.png)

Testing brew is simple, just type `which brew` and see if you get brew path in return. (`which` is a command to check where the binary you want to execute is located)

![which brew](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c106ajwnimu0x45twchz.png)

# Installing Ruby using RVM

Even if you are not writing Ruby on Rails, there is a chance that you might need to use some Rubygems in the future such as cocoapods. So it won't hurt to install ruby first. Moreover, installing ruby will install many other dependencies you may need in the future. 

## RVM - Ruby Version Manager

RVM will allow you to install many ruby versions in your mac / linux. Simply visit rvm website

![rvm website](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/982mqjs1rphq6ll19ckx.png)

and run the highlighted command.

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

When it's done, restart the terminal session (`⌘+w` `⌘+t`) then type `rvm --version` to check if rvm is installed.

![rvm --version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9l5hrvalrur60kp889y.png)

## Ruby

We will use `rvm` to install multiple ruby versions. I usually start installing with older versions (not latest). There are time when openssl may break ruby installation. If you have problem in this step, you need to google for solutions. 

```bash
rvm install 2.7.4
rvm install 3.0.6
rvm install 3.1.4
rvm install 3.2.2
rvm install 3.3.0
```

You don't need to install all of these. But these are what I have. Switching ruby version is simple. You only need to understand these commands. 

```bash
ruby --version # check current version
rvm list # list all installed versions
rvm list known # list all known / installable versions 
rvm use VERSION # eg. `rvm use 3.3.0` will swap to `3.3.0`
rvm --default use VERSION # to setup that version as default every time terminal is opened.
```

![RVM example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rsqw6jofhnkc6b6vdzbw.png)

# Installing Nodejs using NVM

Similar to RVM there is NVM for Nodejs. Fortunately, it's easy to install nvm using homebrew. Just run

```bash
brew install nvm
```

You will need to copy and paste this text into `~/.zshrc`.

![Install nvm](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t6si4j0ds13ac2v9ixc3.png)

To do that just copy the text and then run

```bash
nano ~/.zshrc
```

move the cursor down to the bottom and just paste the text.

![Install nvm](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uowgf6157bvttr2v7xol.png)

Now, save the file and exit. (in `nano` pressing `ctrl+x` will try to exit `nano` but since you've made some changes it will ask if you want to save. the prompt is at the bottom of the screen. Select `yes` and press enter).

If you want to check if `nvm` is working, just try installing some Nodejs. The commands are listed below

```bash
nvm list # list installed versions
nvm ls-remote # list installable versions
nvm install VERSION # eg. `nvm install 20.14.0`
nvm use VERSION # switching version
nvm alias default VERSION # making the selected version default every time terminal is opened.
```

If you are a Node user that depends on .nvmrc to switch versions between projects. Or you are planning to learn nodejs, configuring this will help.

Open `nano ~/.zshrc` again and paste this at the bottom.

```
load-nvmrc() {
  local node_version="$(nvm version)"
  local nvmrc_path="$(nvm_find_nvmrc)"

  if [ -n "$nvmrc_path" ]; then
    local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")

    if [ "$nvmrc_node_version" = "N/A" ]; then
      nvm install
    elif [ "$nvmrc_node_version" != "$node_version" ]; then
      nvm use
    fi
  elif [ "$node_version" != "$(nvm version default)" ]; then
    echo "Reverting to nvm default version"
    nvm use default
  fi
}
add-zsh-hook chpwd load-nvmrc
```

Restart the session and this load-nvmrc hook should be active. When you enter any folder using `cd` it will always look for `.nvmrc` file which usually indicates the Node version inside. eg. `v18.20.3`

It's hard to explain. So sollow the image below to see how it works.

![nvmrc example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lr490qwxvus8e5jtvdi9.png)

# Docker

Though you can install docker via brew and I'm not a big fan of double clicking anything, I still prefer to go to the official website and download the installer. 

[![Docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a75t17c85lxlv0dfg8yl.png)](https://www.docker.com/products/docker-desktop/)

It's easy, simple, safe and fast.

# Postgresql

I prefer having database locally. Sometimes docker just take too much storage. With brew, it's easy to install postgres.

```bash
brew install postgresql@16
brew services start postgresql@16
```

To test if it's working just try `createdb`, `psql`, and `dropdb`

![Test Postgres CLI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ramqi8q3dfboec3fazj6.png)

# Other softwares you might need

Maybe you want to install chrome, vscode, sublime text, etc... just google `brew install SOFTWARENAME` such as search for `brew install chrome`. It will tell you to run install with `--cask`.

![Brew install chrome](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abczamuhks7q9mcxyrwq.png)

The `--cask` option is usually when you are about to install software that has GUIs.

Here are the list that you might want to install

```bash
brew install --cask google-chrome
brew install --cask sublime-text
brew install --cask visual-studio-code
brew install --cask azure-data-studio
brew install --cask postman
brew install --cask microsoft-teams
brew install --cask firefox
brew install --cask iterm2
```

## Sublime

I use Sublime as my main IDE and [HERE](https://gist.github.com/SaKKo/229091392e9ef9d75d1b5c9b5f4c48dd) is my current config.

# What's next

Well.... installing things are easy. First you search in homebrew then if it's not there then you do it manually.

I made this post specially for my team members. If you find this article useful please share.

Thankz
SaKKo