Linux MintUbuntu Based

How To Install NVM on Linux Mint 22

Install NVM on Linux Mint 22

Modern JavaScript development demands flexibility when working with different Node.js versions across multiple projects. Node Version Manager (NVM) emerges as the essential solution for developers working on Linux Mint 22, providing seamless management of multiple Node.js installations. This comprehensive guide walks through every step needed to successfully install and configure NVM on Linux Mint 22, ensuring optimal development environment setup.

The installation process involves downloading the official NVM script, configuring shell environments, and verifying proper functionality. With NVM installed, developers gain the ability to switch between Node.js versions instantly, maintain project-specific requirements, and avoid compatibility conflicts that plague traditional single-version installations.

Understanding NVM and Linux Mint 22 Compatibility

What is Node Version Manager (NVM)?

Node Version Manager represents a POSIX-compliant bash script designed specifically for managing multiple Node.js versions within a single development environment. Unlike traditional package managers that limit users to single Node.js installations, NVM creates isolated environments for each version, preventing conflicts between different projects requiring specific Node.js releases.

The tool operates by creating symbolic links and modifying PATH variables dynamically, allowing instant switching between installed Node.js versions without system-wide changes. This approach ensures clean installations while maintaining the ability to test applications across multiple Node.js releases simultaneously.

Professional development teams widely adopt NVM as the industry standard for Node.js version management, with official endorsement from the Node.js community. The tool supports all major shells including bash, zsh, dash, ksh, and sh, making it compatible with virtually any Linux distribution.

Linux Mint 22 System Requirements

Linux Mint 22, codenamed “Wilma,” builds upon Ubuntu 22.04 LTS foundations, ensuring excellent compatibility with NVM installation procedures. The operating system’s default bash shell environment provides optimal conditions for NVM deployment without additional configuration requirements.

The system requires minimal resources for NVM operation: adequate disk space for multiple Node.js versions, basic networking connectivity for downloads, and standard user privileges. Linux Mint’s APT package management system facilitates easy installation of prerequisites like curl and build tools.

Most Linux Mint 22 installations include necessary dependencies by default, streamlining the NVM setup process compared to minimal server distributions. The stable nature of Linux Mint’s LTS base ensures consistent behavior across different hardware configurations.

System Prerequisites and Preparation

Essential System Requirements

Before installing NVM on Linux Mint 22, verify system compatibility and available resources. The installation requires a POSIX-compliant shell environment, which Linux Mint 22 provides through its default bash configuration. User accounts need sudo privileges for installing prerequisite packages, though NVM itself installs in user space without requiring administrative access.

Network connectivity enables downloading installation scripts and Node.js binaries from official repositories. Ensure adequate disk space allocation, as multiple Node.js versions can consume several gigabytes depending on installation choices. Modern hardware specifications typically exceed NVM requirements, making resource constraints unlikely on contemporary systems.

Installing Required Dependencies

Linux Mint 22 requires specific utilities for successful NVM installation and operation. The curl command-line tool serves as the primary method for downloading installation scripts from the official NVM repository. Install curl using the following command:

sudo apt install curl

Verify curl installation by checking its version:

curl --version

Optional dependencies enhance NVM functionality for specific use cases. The git version control system enables manual NVM installation methods and repository management:

sudo apt install git

Build-essential packages provide compilation tools necessary for Node.js modules with native dependencies:

sudo apt install build-essential

Pre-installation System Cleanup

Remove existing Node.js installations to prevent conflicts with NVM-managed versions. Check for system-installed Node.js packages:

node --version
npm --version

If system Node.js exists, remove it completely:

sudo apt remove nodejs npm
sudo apt autoremove

Clear package cache and update repository information:

sudo apt clean
sudo apt update

This cleanup ensures NVM operates without interference from pre-existing Node.js installations.

Step-by-Step NVM Installation Process

Step 1: Update System Packages

Begin by refreshing Linux Mint 22 package repositories to ensure access to latest software versions. Execute the update command to synchronize package lists:

sudo apt update

Upgrade existing packages to current versions for optimal system stability:

sudo apt upgrade

The update process downloads fresh package metadata from configured repositories, while upgrade installs newer versions of currently installed software. This preparation step prevents dependency conflicts during NVM installation and ensures compatibility with the latest security patches.

Monitor the update process for any error messages indicating repository connectivity issues or authentication problems. Successful completion displays updated package counts and any upgraded software notifications.

Step 2: Install Essential Dependencies

Install curl utility for downloading NVM installation scripts from the official GitHub repository:

sudo apt install curl

Confirm curl installation success by displaying version information:

curl --version

The output should display curl version details, SSL support, and available protocols. This verification ensures proper curl functionality for subsequent NVM script download operations.

Install wget as an alternative download utility for environments where curl may not function properly:

sudo apt install wget

Additional development tools support compilation of native Node.js modules:

sudo apt install build-essential

These packages provide gcc compiler, make utilities, and development headers required for building binary Node.js extensions.

Step 3: Download and Execute NVM Installation Script

Download and execute the official NVM installation script using curl:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash

Alternative installation using wget for systems where curl encounters issues:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash

The installation script performs several automated tasks:

  • Creates ~/.nvm directory structure
  • Downloads NVM files from the official GitHub repository
  • Configures shell profile files automatically
  • Sets up necessary environment variables

Monitor script output for successful completion messages and any potential error notifications. The script typically completes within minutes, depending on network connectivity speeds.

Step 4: Configure Shell Environment

The installation script automatically updates shell profile files with NVM configuration. Verify profile modifications by examining the updated ~/.bashrc file:

cat ~/.bashrc | grep -A 3 'export NVM_DIR'

Manual configuration becomes necessary if automatic profile updates fail. Add the following lines to ~/.bashrc:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

For zsh users, modify ~/.zshrc instead of ~/.bashrc with identical configuration lines. These commands establish the NVM directory location and load NVM functionality into the shell environment.

Reload the shell configuration to activate NVM immediately:

source ~/.bashrc

Alternatively, close and reopen the terminal window to apply profile changes.

Verification and Initial Setup

Verifying NVM Installation Success

Confirm successful NVM installation by checking the version:

nvm --version

The command should display the installed NVM version number, indicating proper installation and shell integration. If the command fails with “command not found” errors, shell configuration requires attention.

Test NVM command availability using the shell builtin verification:

command -v nvm

This command returns “nvm” for successful installations, confirming shell function registration. The verification distinguishes between shell functions and executable binaries, which is important since NVM operates as a shell function rather than a standalone program.

List currently installed Node.js versions to verify NVM repository initialization:

nvm ls

Initially, this command shows no installed versions but confirms NVM functionality.

Troubleshooting Common Installation Issues

Address “command not found” errors by verifying shell profile configurations. Check if the installation script properly modified ~/.bashrc:

tail -10 ~/.bashrc

The output should contain NVM-related export and source commands. If missing, manually add the configuration lines discussed in the previous section.

Restart the terminal application or source the profile file again:

source ~/.bashrc

Permission issues may prevent proper NVM directory creation. Verify ~/.nvm directory existence and permissions:

ls -la ~/.nvm

The directory should exist with user ownership and appropriate read/write permissions.

Installing and Managing Node.js Versions

Installing Node.js with NVM

Install the latest Long Term Support (LTS) version of Node.js using NVM:

nvm install --lts

This command downloads, compiles, and installs the current LTS release, automatically setting it as the active version. The installation process displays progress indicators and completion confirmations.

Install specific Node.js versions by specifying version numbers:

nvm install 18.17.0
nvm install 20.5.1

Install the latest current release (non-LTS) version:

nvm install node

The “node” alias always refers to the newest available version, including pre-release builds. Each installation creates a separate Node.js environment with associated npm package manager.

View available Node.js versions for installation:

nvm ls-remote

This command displays all available Node.js releases, including LTS designations and version aliases.

Managing Multiple Node.js Versions

List all installed Node.js versions on the system:

nvm ls

The output shows installed versions with indicators for the currently active version and default alias assignments. Active versions display with arrows (->), while default versions show with asterisks (*).

Switch between installed Node.js versions during development:

nvm use 18.17.0
nvm use 20.5.1
nvm use --lts

Version switching applies only to the current terminal session unless a default version is established. Each switch updates the PATH variable to point to the selected Node.js installation.

Set a default Node.js version for new terminal sessions:

nvm alias default 18.17.0

The default alias ensures consistent Node.js availability across all new terminal windows.

Verify the currently active Node.js and npm versions:

node --version
npm --version

These commands confirm successful version switching and display exact version numbers.

Advanced Configuration and Usage

Project-Specific Version Management with .nvmrc

Create .nvmrc files to specify Node.js versions for individual projects. Navigate to a project directory and create the configuration file:

echo "18.17.0" > .nvmrc

The .nvmrc file contains a single line specifying the required Node.js version. Team members can then use the project’s specified version automatically:

nvm use

When executed in a directory containing .nvmrc, NVM automatically switches to the specified version. This approach ensures consistent development environments across team members and deployment targets.

Create .nvmrc files for different project requirements:

# For legacy projects
echo "14.21.3" > .nvmrc

# For modern applications
echo "20.5.1" > .nvmrc

# For LTS stability
echo "lts/hydrogen" > .nvmrc

LTS codenames provide stable version references that update automatically when new LTS releases become available.

Advanced NVM Configuration Options

Customize NVM installation directory by setting environment variables before installation:

export NVM_DIR="$HOME/.custom-nvm"

This customization helps organize development tools or comply with organizational standards. Remember to update shell profile configurations accordingly.

Enable bash completion for enhanced command-line productivity:

[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Bash completion provides tab-based autocompletion for NVM commands, version numbers, and aliases. This feature significantly improves workflow efficiency during frequent version switching.

Configure lazy loading to improve shell startup performance for systems with multiple NVM installations:

# Add to ~/.bashrc for lazy loading
nvm() {
    unset -f nvm
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    nvm "$@"
}

Lazy loading delays NVM initialization until first use, reducing terminal startup times.

Troubleshooting Common Issues

Installation and Configuration Problems

Resolve “nvm: command not found” errors by verifying shell profile configurations. Check which shell is currently active:

echo $SHELL

Ensure NVM configuration matches the active shell environment. For bash users, verify ~/.bashrc contains proper NVM initialization:

grep -n "NVM_DIR" ~/.bashrc

For zsh users, check ~/.zshrc instead:

grep -n "NVM_DIR" ~/.zshrc

Permission errors during installation often result from incorrect user privileges or directory ownership. Verify home directory permissions:

ls -ld ~/

Fix ownership issues if necessary:

sudo chown -R $USER:$USER ~/

Network connectivity problems may prevent script downloads or Node.js installations. Test repository accessibility:

curl -I https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh

Use wget as an alternative if curl encounters SSL or proxy issues:

wget --spider https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh

Runtime and Version Management Issues

Address Node.js version conflicts by clearing NVM cache:

nvm cache clear

This command removes cached installation files and temporary downloads that may cause version switching problems.

Fix missing global npm packages after version switches by understanding NVM’s isolation model. Each Node.js version maintains separate global package installations. Reinstall global packages for each version:

npm install -g nodemon
npm install -g typescript

Or migrate packages between versions using NVM’s reinstall-packages feature:

nvm install 20.5.1 --reinstall-packages-from=18.17.0

This command installs a new Node.js version while copying global packages from an existing installation.

Memory issues with multiple installed versions require periodic cleanup. Remove unused Node.js versions:

nvm uninstall 16.20.0

List installed versions to identify candidates for removal:

nvm ls

Focus on keeping only actively used versions plus one LTS version for stability.

Best Practices and Security Considerations

Security-Focused Installation Practices

Always download NVM installation scripts from official GitHub repositories to prevent malicious code execution. Verify script integrity before execution by examining the content:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | less

Review the script for suspicious commands or unexpected network requests. Official NVM scripts contain transparent operations without hidden functionality.

Use HTTPS URLs exclusively for all NVM-related downloads to prevent man-in-the-middle attacks. Avoid HTTP URLs that transmit installation scripts in plaintext.

Keep NVM updated to the latest version for security patches and functionality improvements:

nvm install-latest-npm

Regular updates ensure access to the newest Node.js releases and security fixes.

Development Workflow Integration

Establish team-wide Node.js version standards using .nvmrc files in project repositories. Document version requirements in README files and setup instructions:

## Development Setup
1. Install NVM following the official guide
2. Run `nvm use` in the project directory
3. Install dependencies with `npm install`

This documentation ensures consistent development environments across team members.

Integrate NVM with Continuous Integration (CI) pipelines for automated testing across Node.js versions. Configure CI systems to respect .nvmrc files:

# GitHub Actions example
- name: Setup Node.js
  uses: actions/setup-node@v3
  with:
    node-version-file: '.nvmrc'

Test applications across multiple Node.js versions to ensure compatibility. Create testing matrices that cover LTS versions and current releases.

Maintenance and Uninstallation

Regular NVM Maintenance

Perform routine maintenance to keep NVM functioning optimally and conserve disk space. Update NVM to the latest version periodically:

nvm install-latest-npm

Clean up unused Node.js versions to reclaim disk space:

nvm ls
nvm uninstall 14.21.3
nvm uninstall 16.20.0

Keep only actively used versions plus the current LTS release for stability. Each Node.js installation can consume 50-100MB of disk space, making cleanup important for systems with limited storage.

Clear NVM cache to remove temporary files and corrupted downloads:

nvm cache clear

This maintenance step resolves installation issues and frees additional disk space.

Complete NVM Removal

Remove NVM completely when transitioning to alternative Node.js management solutions. Deactivate NVM in the current session:

nvm deactivate

Remove the NVM directory and all installed Node.js versions:

rm -rf ~/.nvm

Clean NVM configuration from shell profile files:

sed -i '/NVM_DIR/d' ~/.bashrc
sed -i '/nvm.sh/d' ~/.bashrc
sed -i '/bash_completion/d' ~/.bashrc

Reload shell configuration to complete removal:

source ~/.bashrc

Verify complete removal by testing command availability:

nvm --version

The command should return “command not found” indicating successful removal.

Congratulations! You have successfully installed NVM. Thanks for using this tutorial for installing the latest version of NVM (Node Version Manager) on Linux Mint 22. For additional help or useful information, we recommend you check the official NVM website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button