Ora

How do I delete a node version?

Published in Node.js Version Management 5 mins read

To delete a Node.js version, the method you use depends largely on how you initially installed Node.js on your system. The most common installation methods include using a Node Version Manager (NVM), a system-level package manager, or a pre-built installer downloaded from the official Node.js website.

How Do I Delete a Node Version?

Deleting a Node.js version requires a specific approach tailored to its original installation method. The most efficient and recommended way to manage multiple Node.js versions, and thus delete them, is by using a Node Version Manager.


Method 1: Using a Node Version Manager (NVM)

If you installed Node.js using NVM (Node Version Manager), deleting a specific version is straightforward and highly recommended for managing multiple Node.js environments. NVM allows you to switch between different Node.js versions easily without affecting your system's global Node.js installation.

Steps to Delete a Node.js Version with NVM:

  1. List Installed Versions: First, check which Node.js versions are installed using NVM.

    nvm ls

    This command will display a list of all installed Node.js versions, indicating the currently active one.

  2. Deactivate the Version (If Active): If the version you intend to delete is currently active, switch to another version or deactivate it.

    nvm use <another_version>
    # or to deactivate entirely:
    nvm deactivate

    For example, nvm use 18.17.1.

  3. Delete the Node.js Version: Now, you can uninstall the desired version.

    nvm uninstall <version>

    Replace <version> with the specific Node.js version you want to remove (e.g., nvm uninstall 16.14.0).

  4. Remove Default Alias (Optional): If the deleted version was set as your default, you might want to remove that alias or set a new default.

    nvm alias default none
    # or set a new default:
    nvm alias default <new_default_version>

Why NVM is Recommended

NVM isolates Node.js installations, preventing conflicts and making it easy to manage projects that require different Node.js versions. For more information, visit the NVM GitHub repository.


Method 2: Using a System Package Manager

If you installed Node.js using a system-level package manager (e.g., Homebrew on macOS, APT on Debian/Ubuntu, Yum/DNF on RedHat/CentOS), its deletion is handled by that same package manager. These package managers are often listed as primary download options on the Node.js website.

Deleting Node.js via Package Managers:

  • macOS (Homebrew):

    brew uninstall node
    brew prune # Removes old versions and cleans up

    If you have NVM installed, you might need to ensure Homebrew's Node.js isn't conflicting.

  • Debian/Ubuntu (APT):

    sudo apt purge nodejs
    sudo apt autoremove

    The purge command also removes configuration files.

  • RedHat/CentOS (Yum/DNF):

    sudo yum remove nodejs # For older systems using yum
    sudo dnf remove nodejs # For newer systems using dnf
  • Windows (Chocolatey/Scoop):
    If you used a package manager like Chocolatey or Scoop:

    choco uninstall nodejs # For Chocolatey
    scoop uninstall nodejs # For Scoop

Method 3: Using a Pre-built Installer

If you downloaded and ran a pre-built installer package (like a .msi for Windows or a .pkg for macOS) directly from the Node.js website, you'll need to use your operating system's standard uninstallation process.

Deleting Node.js Installed via Pre-built Installer:

  • Windows:

    1. Open the Control Panel.
    2. Navigate to Programs > Programs and Features (or Add or Remove Programs).
    3. Find "Node.js" in the list, select it, and click Uninstall.
    4. Follow the on-screen prompts.
  • macOS:
    Uninstalling a .pkg installer for Node.js can be more involved as it installs files in various system directories. A complete uninstallation typically involves:

    1. Remove the main Node.js binaries:
      sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /usr/local/bin/node /usr/local/bin/npm /usr/local/bin/npx
    2. Remove local Node.js installations (if any):
      sudo rm -rf /usr/local/include/node /usr/local/share/man/man1/node.1
      sudo rm -rf ~/.npm ~/.node-gyp ~/.npmrc
    3. Check for other related files: You may need to check /usr/local/bin, /usr/local/share, and /usr/local/lib for any remaining Node.js or npm related files.

    Caution: Be extremely careful when using sudo rm -rf as incorrect commands can lead to data loss. Ensure you are targeting the correct Node.js-related directories.


Method 4: Manual Deletion (If Installed from Source or Archive)

If you compiled Node.js from source or simply extracted a tarball into a specific directory, you would manually delete the installation directory.

Steps for Manual Deletion:

  1. Identify Installation Directory: Locate the directory where you extracted or compiled Node.js. Common locations might be /usr/local/node or a directory within your home folder.
  2. Remove Directory: Delete the entire directory.
    sudo rm -rf /path/to/your/nodejs/installation

    Replace /path/to/your/nodejs/installation with the actual path.

  3. Clean Up PATH (If Modified): If you manually added Node.js to your system's PATH environment variable, remember to remove the corresponding entry from your shell configuration file (e.g., .bashrc, .zshrc, .profile).

Summary Table of Node.js Deletion Methods:

Installation Method Recommended Deletion Approach Commands/Steps (Examples)
NVM (Node Version Manager) Use NVM's uninstall command. nvm uninstall <version>
nvm deactivate
nvm ls
Package Manager Use the package manager's uninstall command. brew uninstall node
sudo apt purge nodejs
sudo dnf remove nodejs
Pre-built Installer Use OS's uninstallation tool (Windows) or manual file deletion (macOS). Windows: Control Panel > Programs > Uninstall
macOS: sudo rm -rf /usr/local/lib/node ...
Manual (Source/Archive) Manually delete the installation directory. sudo rm -rf /path/to/node/installation
Remove PATH entry

By understanding how Node.js was initially installed on your system, you can choose the correct method to delete a specific version effectively.