DEV Community

Cover image for How to Install and Use NVM Globally on Your System
Srijan Karki
Srijan Karki

Posted on

How to Install and Use NVM Globally on Your System

Node Version Manager (NVM) allows you to install and manage multiple versions of Node.js on your system. Since NVM is installed globally, it does not depend on a specific project folder, making it easier to switch between Node.js versions across different projects.

Steps to Install and Use NVM

1️⃣ Open Your Terminal

Depending on your operating system, open the appropriate terminal:

  • Windows: Open Git Bash, Command Prompt, or PowerShell (if using nvm-windows, use Command Prompt instead).
  • Mac: Open Terminal.
  • Linux: Open a terminal window.

2️⃣ Run the Installation Commands

Run the following commands one by one to install NVM:

curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source ~/.bashrc  # If using Bash shell
source ~/.zshrc   # If using Zsh shell (Mac users)
Enter fullscreen mode Exit fullscreen mode

These commands will install NVM and make it available in your terminal.

3️⃣ Install and Use Node.js 20

Once NVM is installed, you can install Node.js version 20:

nvm install 20
nvm use 20
Enter fullscreen mode Exit fullscreen mode

To make Node.js 20 the default version for all new terminal sessions, run:

nvm alias default 20
Enter fullscreen mode Exit fullscreen mode

4️⃣ Verify the Installation

To check if Node.js 20 is active, run:

node -v
Enter fullscreen mode Exit fullscreen mode

It should output something like:

v20.x.x
Enter fullscreen mode Exit fullscreen mode

5️⃣ Reinstall Dependencies in Your Project

If you are working on a specific project (e.g., admin-panel), navigate to the project folder and reinstall dependencies:

cd "D:\Documents\company projects\admin-panel"
rm -rf node_modules package-lock.json pnpm-lock.yaml .next
pnpm install
pnpm dev
Enter fullscreen mode Exit fullscreen mode

This should resolve any version-related issues.

Troubleshooting: Missing .bashrc File

If you encounter the error:

bash: /c/Users/Shishir/.bashrc: No such file or directory
Enter fullscreen mode Exit fullscreen mode

Try the following solutions:

1️⃣ Use .bash_profile or .zshrc

If .bashrc is missing, try:

source ~/.bash_profile  # For Bash users
source ~/.zshrc         # For Zsh users (Mac/Linux)
Enter fullscreen mode Exit fullscreen mode

2️⃣ Manually Create .bashrc (For Windows Git Bash)

If the issue persists, manually create the .bashrc file:

touch ~/.bashrc
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.bashrc
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Then try installing and using Node.js again:

nvm install 20
nvm use 20
Enter fullscreen mode Exit fullscreen mode

3️⃣ Restart Your Terminal

If none of the above steps work, close and reopen your terminal, then run:

nvm install 20
nvm use 20
Enter fullscreen mode Exit fullscreen mode

Conclusion

By following these steps, you can successfully install and manage Node.js versions using NVM. This method ensures you have flexibility across different projects without interfering with system-wide installations. If you face any issues, feel free to restart your terminal or reinstall NVM.

🚀 Happy coding!

Top comments (0)