Nodenv CheatSheet
Here is a quick reference guide to the Nodenv CLI tool.
⚡ Note: Swap out specify_abc
with the specific abc
variable for the listed commands.
- Example: swap
specify_version
with14.5.0
to install Node.js version14.5.0
.
Table of Contents
- Common Nodenv Commands
- What is Nodenv?
- Install & Setup Nodenv
- Usage - Install & Setup a Node.js version
- Nodenv Plugins
Common Nodenv Commands
Action | Command |
---|---|
List all available Node.js versions | nodenv install --list |
List installed Node.js versions | nodenv versions |
Install a specific Node.js version | nodenv install specify_version |
Set a global Node.js version | nodenv global specify_version |
Set a local (folder-specific) Node.js version | nodenv local specify_version |
Uninstall a specific Node.js version | nodenv uninstall specify_version |
Switch to a specific Node.js version | nodenv shell specify_version |
What is Nodenv?
Since Node.js is notorious for breaking changes, it is important to be able to manage multiple Node.js versions on your machine.
That is where Nodenv comes in. It is a tool that allows you to install and switch between multiple Node.js versions seamlessly.
Install & Setup Nodenv
⚠️ Warning: Remove any existing installations of Node.js before installing nodenv! Having different Node.js installations can lead to conflict issues.
- Install nodenv with Homebrew
- Set up nodenv shell integration
- Implement the changes by restarting the Terminal window
- Verify that nodenv is set up correctly using the nodenv-doctor script.
# Update Homebrew
brew update && brew upgrade
# Install nodenv
brew install nodenv
# Initialization command
nodenv init
# Append the following line into the shell's rc/profile
eval "$(nodenv init -)"
# ----
# For Zsh users
echo 'eval "$(nodenv init -)"' >> ~/.zshrc
cat < ~/.zshrc
# For Bash users
echo 'eval "$(nodenv init -)"' >> ~/.bash_profile
cat < ~/.bash_profile
⚡ Now, close & open a new Terminal window for the changes to take place.
💪 Debug: Verify that Nodenv is properly set up by running the nodenv-doctor
script:
curl -fsSL https://github.com/nodenv/nodenv-installer/raw/master/bin/nodenv-doctor | bash
Usage - Install & Setup a Node.js version
Now you're ready to install specific Node.js versions!
Inside project
folder, install Node.js version 14.5.0
:
cd project/
nodenv install 14.5.0
nodenv local 14.5.0
Alright! Your Mac is now armed with Node.js!
Which Node.js version should I use?
Use the latest LTS (long-term support) Node.js version when in doubt.
Find it here: Node.js
If you are going to use a framework like React, Vue, or Angular, you should check their documentation for the recommended Node.js version.
Nodenv Plugins
What are plugins? Plugins are additional features that you can add to nodenv to enhance its functionality. You can find a list of plugins here: Plugins · nodenv/nodenv Wiki
Action | Command |
---|---|
List available nodenv plugins | nodenv plugins |
Set Nodenv Homebrew Tap | brew tap nodenv/nodenv |
Install a nodenv plugin | brew install specify_plugin |
Enable a nodenv plugin | nodenv specify_plugin specify_command |
Install Nodenv Plugins - Example: nodenv-nvmrc
brew tap nodenv/nodenv
brew install nodenv-nvmrc