Node version issues
To run any Angular project, we need to have a specific version of Node.js installed.
Installing Node.js requires admin rights, but we can only install and use one version at a time.
About NVM
NVM is a tool that manages multiple Node versions on your device. It’s useful because different projects may require different Node versions, and using a single version might not yield correct results.
To switch between different versions smoothly and quickly, we can use Node Version Manager (nvm).
NVM Installation (Without Admin Rights)
Install bash terminal
- If using windows install bash terminal
Clone nvm Repository
Run the following commands in cmd or bash terminal.
This command will clone the nvm repository to a
~/.nvm
directory on your device.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Create .bashrc
file in Home Directory
Windows Home Directory :
C:\Users\<Your_Username>\
Create a .bashrc file with the following code
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"
Reopen the Bash
Open the bash terminal by using
bash
keyword in cmd.check whether nvm is working by verifying its version.
NVM Commands
We can use following nvm commands in bash.
nvm version
nvm -v
Install latest node version
nvm install latest
Install X.Y.Z
node version
nvm install vX.Y.Z
List all node versions
nvm list
or
nvm ls node
Set default node version
nvm alias default vX.Y.Z
Use a particular node version
Example - nvm use v20.14.0
nvm use vA.B.C
References
- Freecode camp Installation guide article - Link