set-nodeversion
Switch active Node.js version
TLDR
Use a specific version of Node.js in the current PowerShell session
Use the latest installed Node.js version 20.x
Set the default Node.js version for the current user (only applies to future PowerShell sessions)
Set the default Node.js version for all users (must be run as Administrator/root and only applies to future PowerShell sessions)
SYNOPSIS
set-nodeversion <version|alias> [options]
PARAMETERS
<version|alias>
The specific Node.js version string (e.g., 16.14.0, lts/gallium) or a predefined alias (e.g., default, current, lts) to set as the active version.
-g, --global
Sets the specified Node.js version as the system-wide default, affecting new shell sessions.
-l, --local
Sets the Node.js version for the current project directory, often by creating or updating a configuration file (e.g., .nvmrc).
-p, --persist
Makes the version selection persistent across shell sessions, typically by updating shell startup scripts.
-h, --help
Displays a help message showing command usage and available options.
DESCRIPTION
The set-nodeversion command is a conceptual or custom utility designed to facilitate switching between different installed Node.js versions on a Linux system. While not a standard command shipped with most Linux distributions, it represents the core functionality provided by Node.js version managers like nvm (Node Version Manager) or n. Its primary purpose is to update environment variables, typically the PATH, or manage symbolic links, to point to a specific Node.js installation. This allows developers to easily switch contexts for different projects that might require distinct Node.js versions, ensuring compatibility and avoiding conflicts. Without such a mechanism, managing multiple Node.js versions manually would be cumbersome, involving frequent manual PATH modifications or reinstallation. A set-nodeversion utility abstracts this complexity, offering a simple interface to manage the active Node.js runtime.
CAVEATS
set-nodeversion is not a standard Linux command; it is typically a custom script or an alias representing the functionality of Node.js version managers. Therefore, its availability, exact syntax, and options can vary significantly based on how it's implemented (e.g., as part of nvm, n, or a custom shell script). Users should consult the documentation for their specific Node.js version management tool. Improper use could lead to broken Node.js environments or conflicting package installations.
COMMON IMPLEMENTATIONS
While set-nodeversion itself is not a direct command, its functionality is best exemplified by:
- nvm use <version|alias>: Activates a specific Node.js version for the current shell session.
- n <version|alias>: Switches to and uses a specific Node.js version, often making it the system default (depending on installation method).
- nvm alias default <version>: Sets a specific version to be used as the default for new shell sessions.
HISTORY
The need for commands like set-nodeversion arose from the challenges of managing multiple Node.js projects, each potentially requiring a specific runtime version, in a single development environment. Early Node.js development often involved manual installation and PATH management, which was cumbersome and prone to conflicts. This led to the development of dedicated version management tools like nvm (released around 2010) and n (released around 2012). These tools provided simple command-line interfaces to install, switch, and manage Node.js versions, effectively embodying the conceptual set-nodeversion functionality. The widespread adoption of these tools made multi-version Node.js development much more streamlined, establishing a de facto standard for how developers interact with their Node.js runtimes.