DEV Community

SaKKo
SaKKo

Posted on

How to setup Mac for development in 2024. (Ruby on Rails and NodeJS)

It's been awhile (Since my previous post) 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

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

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

And just run this command in terminal.



xcode-select --install


Enter fullscreen mode Exit fullscreen mode

xcode-select --install

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

xcode-select --install popup

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

Simply run this command in terminal



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


Enter fullscreen mode Exit fullscreen mode

Image description

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

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



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


Enter fullscreen mode Exit fullscreen mode

Run Homebrew zprofile script

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

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

and run the highlighted command.



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


Enter fullscreen mode Exit fullscreen mode

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

rvm --version

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.



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


Enter fullscreen mode Exit fullscreen mode

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.



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.


Enter fullscreen mode Exit fullscreen mode

RVM example

Installing Nodejs using NVM

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



brew install nvm


Enter fullscreen mode Exit fullscreen mode

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

Install nvm

To do that just copy the text and then run



nano ~/.zshrc


Enter fullscreen mode Exit fullscreen mode

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

Install nvm

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



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.


Enter fullscreen mode Exit fullscreen mode

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


Enter fullscreen mode Exit fullscreen mode

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

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

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.



brew install postgresql@16
brew services start postgresql@16


Enter fullscreen mode Exit fullscreen mode

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

Test Postgres CLI

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

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



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

Enter fullscreen mode Exit fullscreen mode




Sublime

I use Sublime as my main IDE and HERE 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

Top comments (0)