Logo

dev-resources.site

for different kinds of informations.

Upgrading Node.js on Linux using NVM

Published at
10/20/2024
Categories
node
nvm
npm
linux
Author
dessad07
Categories
4 categories in total
node
open
nvm
open
npm
open
linux
open
Author
8 person written this
dessad07
open
Upgrading Node.js on Linux using NVM

If you're trying to upgrade Node.js from version 12 to a more recent version (e.g., 18 LTS) on a Linux distribution like Parrot OS and encountering issues along the way, this guide is for you. It will cover each step in detail, including common problems and solutions.

Prerequisites

Before you begin, make sure you have the following:

  • A Linux distribution (e.g., Parrot OS)
  • An existing installation of Node.js version 12
  • Administrative access to your system

1. Installing NVM

Check your package manager:
Update your package manager to ensure you have the latest package information.

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Install NVM (Node Version Manager):
NVM will allow you to easily switch between Node.js versions.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh
Enter fullscreen mode Exit fullscreen mode
source ~/.bashrc # Source NVM in your current session
Enter fullscreen mode Exit fullscreen mode

List available Node.js versions:
See the available Node.js versions for installation.

nvm ls-remote
Enter fullscreen mode Exit fullscreen mode

2. Upgrading Node.js

Install Node.js version 18:
Replace 18 with the version you want.

nvm install 18
Enter fullscreen mode Exit fullscreen mode

Set Node.js 18 as the default version:
To set it as the default:

nvm alias default 18
Enter fullscreen mode Exit fullscreen mode

Or, for the current session:

nvm use 18
Enter fullscreen mode Exit fullscreen mode

Update npm (Node Package Manager):

npm install -g npm@latest
Enter fullscreen mode Exit fullscreen mode

3. Troubleshooting Common Issues

NVM Command Not Found

If you encounter the "nvm command not found" error:

  • Source NVM in your shell profile (e.g., ~/.bashrc or ~/.zshrc) or use the correct shell-specific configuration file.

Node.js Version Rolls Back to 12

If Node.js version rolls back to 12 after closing the terminal:

  • Check that the NVM sourcing commands are present and correctly placed in your shell profile.
  • Ensure the shell profile is sourced when opening a new terminal session.

Issues with .bashrc

If you face issues with ~/.bashrc:

  • Create the ~/.bashrc file if it doesn't exist.
touch ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  • Add the NVM sourcing commands to ~/.bashrc.
nano ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  • Source ~/.bashrc to apply changes to your current session.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
Enter fullscreen mode Exit fullscreen mode
  • After you've saved the ~/.bashrc file, you need to source it to apply the changes to your current terminal session.
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  • Verify NVM installation and set the default Node.js version.
nvm --version
Enter fullscreen mode Exit fullscreen mode

These steps should help you upgrade Node.js and address common problems that may arise during the process. Remember to test your Node.js projects to ensure compatibility with the new version.

nvm Article's
30 articles in total
Favicon
"nvm use" does not work with nvm-windows
Favicon
📦 ASDF: Gerenciando versões de linguagens e ferramentas num lugar só
Favicon
Setup NVM in your organization/admin system's like a pro
Favicon
Eligiendo la versión por defecto de node con nvm
Favicon
Migrating from nvm to mise
Favicon
OMZ: Some Plugins that I forget about
Favicon
Install/Use Any Version of Node.js with nvm (Node Version Manager)
Favicon
Brave New World: Environments
Favicon
Upgrading Node.js on Linux using NVM
Favicon
Meet phpvm: Your New PHP Best Friend Forever!
Favicon
Changing the Angular CLI version
Favicon
Como Instalar o Node.js LTS Usando o NVM
Favicon
How to install Node.js, NPM and NVM on Windows (node version manager)
Favicon
Seamlessly Manage Node.js Versions on Windows with nvm
Favicon
How to use NVM in Laravel Forge
Favicon
Understanding NPM and NVM: Essential Tools for Node.js Development
Favicon
Advanced NVM Commands for Efficient Node.js Version Management
Favicon
Why Specifying the Node.js Version is Essential
Favicon
NVM Install On Your PC
Favicon
Manage Node.js version for a project using NVM and .nvmrc file
Favicon
A simple, cross-platform, and well-tested version manager for multiple SDKs.
Favicon
Node Version Manager (nvm) overview
Favicon
NVM tips and tricks
Favicon
nvm으로 node 버전 관리하기
Favicon
HOW TO INSTALL NVM ON WINDOWS
Favicon
Installing and Managing Different Versions of Node.js with NVM
Favicon
✨ Consistency and Efficiency with .nvmrc
Favicon
NVM – Node Version Manager
Favicon
Setup Node and NVM with Fish Shell
Favicon
nvm 설치, 2024-01-24

Featured ones: