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)