DEV Community

Udara Dananjaya
Udara Dananjaya

Posted on

πŸš€ How to Install Node.js Using NVM (Step-by-Step Guide)

If you’ve ever struggled with managing multiple Node.js versions or faced compatibility issues across projects, NVM (Node Version Manager) is your best friend.

In this guide, I’ll walk you through a simple, reliable way to install Node.js using NVM and get your project up and running smoothly.


πŸ”§ Step 1: Install NVM

Start by installing NVM using the official install script:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

This command downloads and runs the installer directly from the official repository.


πŸ”§ Step 2: Load NVM (Without Restarting Terminal)

After installation, you don’t need to restart your terminal. Just run:

\. "$HOME/.nvm/nvm.sh"
Enter fullscreen mode Exit fullscreen mode

This loads NVM into your current shell session.


πŸ”§ Step 3: Install Node.js

Now install the latest Node.js version (in this case, version 24):

nvm install 24
Enter fullscreen mode Exit fullscreen mode

πŸ”§ Step 4: Use the Installed Version

Switch to the installed version:

nvm use 24
Enter fullscreen mode Exit fullscreen mode

πŸ”§ Step 5: Verify Installation

Make sure everything is working:

node -v
npm -v
Enter fullscreen mode Exit fullscreen mode

You should see something like:

v24.x.x
10.x.x
Enter fullscreen mode Exit fullscreen mode

⚠️ Important: Make It Permanent

If you skip this step, NVM won’t load automatically when you open a new terminal.

Add the following lines to your ~/.zshrc file:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Enter fullscreen mode Exit fullscreen mode

Then reload your configuration:

touch ~/.zshrc
source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

βœ… Back to Your Project

Once Node.js is set up, you can return to your project and run:

cd nextjs-boilerplate
npm install
npm run dev
Enter fullscreen mode Exit fullscreen mode

Your app should now start without any issues πŸŽ‰


πŸ’‘ Final Thoughts

Using NVM gives you flexibility and control over your development environment. Whether you're switching between projects or testing different Node versions, it makes the process seamless.

If you're working with modern frameworks like Next.js, having the correct Node version can save you from a lot of headaches.

Happy coding! πŸš€

Top comments (0)