How to install Node.js and NPM with MacOS’s new terminal — zsh

AJ Keller
3 min readJan 7, 2020

--

After 7 years, I finally caved and got a new Mac laptop. Little did I realize but this means that I would have to adapt to using the new zsh shell instead of the classic bash that I’ve been using… well, my whole career. Instead of retroactively opting out of this new shell, I decided to embrace change and learn how to use it.

Prerequisites

Make sure you have command line tools installed by typing git into the terminal.

git

This will prompt you to install command-line tools when the command fails to work.

How to Tell What Shell Your Terminal Is In

This only applies to people wanting to upgrade from bash to zsh.

To see what shell your terminal currently is in, from the command line type in:

echo $0

If you’re in the bash shell, you’ll see printed out:

-bash

If you’re in the zsh shell, you’ll see printed out:

-zsh

Switch Your Default Shell To zsh

To switch your shell to the zsh shell, you may enter:

chsh -s /bin/zsh

To switch back to the bash shell, you may enter:

chsh -s /bin/zsh

TL;DR installation

If you’re like me and don’t want to read an article but blindly copy and paste something into your terminal, do that with the following code snippet to install everything you need to be happy. Comment below if you run into any troubles.

cd ~/
mkdir .antigen
cd .antigen
curl -L git.io/antigen > antigen.zsh
touch ~/.zshrc
echo "source ~/.antigen/antigen.zsh" >> ~/.zshrc
echo "# Load the oh-my-zsh's library." >> ~/.zshrc
echo "antigen use oh-my-zsh" >> ~/.zshrc
echo "# Bundles from the default repo (robbyrussell's oh-my-zsh)." >> ~/.zshrc
echo "antigen bundle lukechilds/zsh-nvm" >> ~/.zshrc
echo "antigen bundle git" >> ~/.zshrc
echo "antigen bundle heroku" >> ~/.zshrc
echo "antigen bundle pip" >> ~/.zshrc
echo "antigen bundle lein" >> ~/.zshrc
echo "antigen bundle command-not-found" >> ~/.zshrc
echo "# Syntax highlighting bundle." >> ~/.zshrc
echo "antigen bundle zsh-users/zsh-syntax-highlighting" >> ~/.zshrc
echo "# Load the theme." >> ~/.zshrc
echo "antigen theme robbyrussell" >> ~/.zshrc
echo "# Tell Antigen that you're done." >> ~/.zshrc
echo "antigen apply" >> ~/.zshrc
nvm install --lts

Step by step installation

I created a folder under my home directory called dev , something like this:

mkdir ~/.antigen && cd ~/.antigen

Next, you’ll want to add this really nifty package manager for zsh called antigen:

curl -L git.io/antigen > antigen.zsh

Now we’re going to configure our .zshrc file:

nano ~/.zshrc

As far as I can tell, .zshrc is the new .bashrc , each of these is run at the beginning of each new terminal instance.

Then you’ll want to copy and paste the following into your .zshrc file:

source ~/.antigen/antigen.zsh# Load the oh-my-zsh's library.antigen use oh-my-zsh# Bundles from the default repo (robbyrussell's oh-my-zsh).antigen bundle lukechilds/zsh-nvmantigen bundle gitantigen bundle herokuantigen bundle pipantigen bundle leinantigen bundle command-not-found# Syntax highlighting bundle.antigen bundle zsh-users/zsh-syntax-highlighting# Load the theme.antigen theme robbyrussell# Tell Antigen that you're done.antigen apply

Restart your terminal. You’ll see a bunch of applications, any that are not defined in your .zhsrc file, get installed the first time the terminal is run. Now you can finally install Node.js and NPM with a single line using nvm!

nvm install --lts

Boom, now you’re ready to roll and won’t have permissions issues when using NPM packages. Let me know if you have any issues running the above code in the comment section below and I’ll be sure to update the article.

Doing More with ZSH

At Neurosity we use Python, a lot. Check out Getting Anaconda to work with Oh My ZSH on Mac OS X for working with anaconda on your computer.

--

--

AJ Keller

Co-founder of Neurosity | Friend of Dogs | On a mission to accelerate the advent of thought computing.