Node.js (node
) is a runtime environment for Javascript. With Node.js comes Node Package Manager (NPM), which is a software registry of easily-accessible, open-source packages. You don’t need to know too much about Node.js other than it uses Javascript 🤪
See if you have node
already installed! Run node --version
and make sure it’s the version you intend for it to be. If you have node
, but want to use NVM, make sure you uninstall existing versions of node
and npm
before installing NVM.
You can download Node.js at its official site, but it’s recommended to install it through Node Version Manager (NVM). NVM allows you to, like the name suggests, manage the node versions. You can easily upgrade node versions as they release, or even roll back to older versions if necessary (sometimes it is!).
You can follow this guide to install NVM or continue reading below (which is exactly the same thing).
Open up a terminal and run this command
curl -o- <https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh> | bash
OR this command
wget -qO- <https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh> | bash
You should have curl
already installed, otherwise install it here.
After installing NVM, it should attempt to add these lines to your profile file(~/.bash_profile
, ~/.zshrc
, ~/.profile
, or ~/.bashrc
). Double check to make sure you have them
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 don’t have these lines, you can manually add them in OR run these 2 commands
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh" # This loads nvm
Then source whatever profile file contains these lines by source ~/.bashrc
or source ~/.zshrc
(or some other profile file). Alternatively, you can just restart your terminal by exiting and reopening it.