Node.js
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.
INFO
Here we will install nvm to use multiple Node.js version.
You can install basic Node.js package but with NVM, you can change Node.js version when you want. Check last version on NVM GitHub and change it if you want latest.
Here, the NVM version is 0.40.1 and Node.js version is 20.17.0 LTS.
Installation
Download NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bashAdd this into ~/.zshrc
INFO
If NVM is already in ~/.zshrc, you can skip this step.
vim ~/.zshrcexport 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 nvmReload ~/.zshrc
source ~/.zshrcUsage
Now you can use nvm, install Node.js v20.17.0 and config nvm to use it.
List all Node.js versions
nvm ls-remoteInstall Node.js v20.17.0
nvm install 20.17.0Use Node.js v20.17.0
nvm use 20.17.0Set v20.17.0 as default
nvm alias default 20.17.0Use default Node.js version
nvm use defaultCheck Node.js version
nvm ls
node -vInstall another version
If you want to install another version, you can use nvm install command.
nvm install 14.17.0And to use it
nvm use 14.17.0Usage with absolute path
If you want to use Node.js with absolute path, you can use nvm which command.
nvm which 20.17.0You can use this path to run Node.js.
/home/user/.nvm/versions/node/v20.17.0/bin/node ./index.jsErrors
If you have an error like nvm: command not found, you can check if nvm is in ~/.zshrc.
cat ~/.zshrcIf it's not there, you can add it.
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