### Install and switch version with nvm install Source: https://nvm.sh Output displayed when nvm install detects .nvmrc and installs the required version if not already present. ```bash $ nvm install Found '/path/to/project/.nvmrc' with version <5.9> Downloading and installing node v5.9.1... Downloading https://nodejs.org/dist/v5.9.1/node-v5.9.1-linux-x64.tar.xz... #################################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v5.9.1 (npm v3.7.3) ``` -------------------------------- ### Install Node.js versions Source: https://nvm.sh Commands to install the latest or specific versions of Node.js. ```bash nvm install node # "node" is an alias for the latest version ``` ```bash nvm install 14.7.0 # or 16.3.0, 12.22.1, etc ``` -------------------------------- ### Install nvm via script Source: https://nvm.sh Use cURL or Wget to download and execute the nvm installation script. ```bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash ``` ```bash wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash ``` -------------------------------- ### Install dependencies Source: https://nvm.sh Install Urchin and other required dependencies for running tests. ```bash npm install ``` -------------------------------- ### Perform Offline Installation Source: https://nvm.sh Install Node.js versions using only local cache, useful for air-gapped environments. ```bash nvm install --offline 14.7.0 ``` ```bash nvm install --offline --lts ``` -------------------------------- ### Manage io.js Versions Source: https://nvm.sh Install and migrate packages for io.js, the historical fork of Node.js. ```bash nvm install iojs ``` ```bash nvm install --reinstall-packages-from=iojs iojs ``` -------------------------------- ### Perform manual nvm installation Source: https://nvm.sh Clone the repository and load nvm manually in the current session. ```bash export NVM_DIR="$HOME/.nvm" && ( git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR" cd "$NVM_DIR" git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)` ) && \. "$NVM_DIR/nvm.sh" ``` -------------------------------- ### Manage Node.js versions with nvm Source: https://nvm.sh Commands to install and switch between different Node.js versions. ```bash $ nvm install 24 Now using node v24.14.0 (npm v11.9.0) $ node -v v24.14.0 $ nvm use 22 Now using node v22.22.1 (npm v10.9.4) $ node -v v22.22.1 $ nvm use 20 Now using node v20.20.1 (npm v10.8.2) $ node -v v20.20.1 ``` -------------------------------- ### Install nvm via curl Source: https://nvm.sh The standard installation command for nvm, which may fail if host resolution is blocked. ```bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: raw.githubusercontent.com ``` -------------------------------- ### Install latest LTS version Source: https://nvm.sh Installs the latest LTS version and migrates packages from the current version. ```bash nvm install --reinstall-packages-from=current 'lts/*' ``` -------------------------------- ### List available Node.js versions Source: https://nvm.sh Displays all remote versions of Node.js available for installation. ```bash nvm ls-remote ``` -------------------------------- ### Install nvm via Ansible Source: https://nvm.sh An Ansible task to automate the installation of nvm using the official install script. ```yaml - name: Install nvm ansible.builtin.shell: > curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash args: creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh" ``` -------------------------------- ### Force install Node.js from source Source: https://nvm.sh Use this command when official binary packages fail due to shared library incompatibilities. ```bash nvm install -s 0.8.6 ``` -------------------------------- ### Migrate Global Packages During Installation Source: https://nvm.sh Use the --reinstall-packages-from flag to automatically migrate global npm packages from an existing Node version to a new one during installation. ```bash nvm install --reinstall-packages-from=node node ``` ```bash nvm install --reinstall-packages-from=5 6 nvm install --reinstall-packages-from=iojs v4.2 ``` ```bash nvm install --reinstall-packages-from=default --latest-npm 'lts/*' ``` -------------------------------- ### List Node Versions Source: https://nvm.sh View installed or remotely available Node.js versions. ```bash nvm ls ``` ```bash nvm ls-remote ``` -------------------------------- ### Install nvm on Alpine Linux 3.13+ Source: https://nvm.sh Install required build dependencies and nvm on Alpine Linux 3.13 or newer. ```bash apk add -U curl bash ca-certificates openssl ncurses coreutils python3 make gcc g++ libgcc linux-headers grep util-linux binutils findutils curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash ``` -------------------------------- ### Install nvm on Alpine Linux 3.5 - 3.12 Source: https://nvm.sh Install required build dependencies and nvm on older Alpine Linux versions using python2. ```bash apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash ``` -------------------------------- ### Verify nvm Installation Source: https://nvm.sh Command to verify that nvm is correctly installed and available as a shell function. ```bash command -v nvm ``` -------------------------------- ### Verify Node.js architecture Source: https://nvm.sh Confirms that the installed Node.js binary is running on the x64 architecture. ```bash $ node -p process.arch x64 ``` -------------------------------- ### Configure Default Global Packages Source: https://nvm.sh Define a list of packages to be installed automatically with every new Node version by editing the default-packages file. ```text # $NVM_DIR/default-packages rimraf object-inspect@1.0.2 stevemao/left-pad ``` -------------------------------- ### Run nvm development container Source: https://nvm.sh Start and enter an interactive session within the nvm-dev container. ```bash $ docker run -h nvm-dev -it nvm-dev nvm@nvm-dev:~/.nvm$ ``` -------------------------------- ### Locate Node.js executable Source: https://nvm.sh Prints the path to the installed executable for a specific version. ```bash nvm which 12.22 ``` -------------------------------- ### Open shell with Rosetta Source: https://nvm.sh Starts a zsh session using the x86_64 architecture via Rosetta 2. ```bash $ arch -x86_64 zsh ``` -------------------------------- ### Install Rosetta 2 on Apple Silicon Source: https://nvm.sh Required for running Intel-based binaries on Apple Silicon Macs. ```bash $ softwareupdate --install-rosetta ``` -------------------------------- ### Manually uninstall nvm Source: https://nvm.sh Unloads the nvm command and removes the installation directory. ```bash $ nvm_dir="${NVM_DIR:-~/.nvm}" $ nvm unload $ rm -rf "$nvm_dir" ``` -------------------------------- ### Upgrade nvm manually Source: https://nvm.sh Updates the nvm installation to the latest version using git. ```bash ( cd "$NVM_DIR" git fetch --tags origin git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)` ) && \. "$NVM_DIR/nvm.sh" ``` -------------------------------- ### Install nvm in Docker for CI/CD Source: https://nvm.sh A robust Docker configuration for CI/CD environments that supports interactive and non-interactive usage. ```dockerfile FROM ubuntu:latest ARG NODE_VERSION=20 # install curl RUN apt update && apt install curl -y # install nvm RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash # set env ENV NVM_DIR=/root/.nvm # install node RUN bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION" # set ENTRYPOINT for reloading nvm-environment ENTRYPOINT ["bash", "-c", "source $NVM_DIR/nvm.sh && exec \"$@\"", "--"] # set cmd to bash CMD ["/bin/bash"] ``` -------------------------------- ### Install older Node.js on Apple Silicon Source: https://nvm.sh Compiles an older Node.js version from source with the shared-zlib flag to avoid compilation errors. ```bash $ nvm install v12.22.1 --shared-zlib ``` -------------------------------- ### Install nvm in Docker Source: https://nvm.sh Configure nvm for non-interactive bash shells by setting the BASH_ENV variable. ```dockerfile # Use bash for the shell SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Create a script file sourced by both interactive and non-interactive bash shells ENV BASH_ENV "${HOME}/.bash_env" RUN touch "${BASH_ENV}" RUN echo '. "${BASH_ENV}"' >> ~/.bashrc # Download and install nvm RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | PROFILE="${BASH_ENV}" bash RUN echo node > .nvmrc RUN nvm install ``` -------------------------------- ### Handle Homebrew zsh directory insecurity Source: https://nvm.sh Addresses warnings about insecure zsh directories caused by Homebrew installations. ```text zsh compinit: insecure directories, run compaudit for list. Ignore insecure directories and continue [y] or abort compinit [n]? y ``` -------------------------------- ### Use System Node Version Source: https://nvm.sh Switch to or execute commands using the system-installed version of Node.js. ```bash nvm use system nvm run system --version ``` -------------------------------- ### Configure io.js binary mirror Source: https://nvm.sh Set the NVM_IOJS_ORG_MIRROR environment variable to download io.js binaries from a custom source. ```bash export NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3 NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3 ``` -------------------------------- ### Create Shell Configuration Files Source: https://nvm.sh Commands to initialize missing shell configuration files on macOS. ```bash touch ~/.zshrc ``` ```bash touch ~/.bash_profile ``` ```bash touch ~/.bashrc ``` -------------------------------- ### Run test suites Source: https://nvm.sh Commands to execute fast, slow, or all tests from the repository root. ```bash npm run test/fast ``` ```bash npm run test/slow ``` ```bash npm test ``` -------------------------------- ### Use and execute Node.js versions Source: https://nvm.sh Commands to switch the active version or execute commands in a specific version context. ```bash nvm use node ``` ```bash nvm run node --version ``` ```bash nvm exec 4.2 node --version ``` -------------------------------- ### Verify resolv.conf contents Source: https://nvm.sh Check the current configuration of the resolv.conf file. ```bash cat /etc/resolv.conf ``` -------------------------------- ### List Docker images Source: https://nvm.sh Verify the nvm-dev image is available after the build process. ```bash $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nvm-dev latest 9ca4c57a97d8 7 days ago 650 MB ``` -------------------------------- ### Build nvm development Docker image Source: https://nvm.sh Build the Docker image from the root of the nvm repository. ```bash $ docker build -t nvm-dev . ``` -------------------------------- ### Apply .nvmrc version with nvm use Source: https://nvm.sh Output displayed when nvm use detects and applies the version defined in .nvmrc. ```bash $ nvm use Found '/path/to/project/.nvmrc' with version <5.9> Now using node v5.9.1 (npm v3.7.3) ``` -------------------------------- ### Configure shell profile for nvm Source: https://nvm.sh Add these lines to your shell profile to initialize nvm. The --no-use flag prevents automatic version selection. ```bash export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm ``` ```bash export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # This loads nvm, without auto-using the default version ``` -------------------------------- ### Configure Node binary mirror Source: https://nvm.sh Set the NVM_NODEJS_ORG_MIRROR environment variable to download binaries from a custom source. ```bash export NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install node NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 4.2 ``` -------------------------------- ### Configure ~/.npmrc for nvm compatibility Source: https://nvm.sh Avoid setting the prefix in ~/.npmrc as it can cause conflicts with nvm. ```text prefix='some/path' ``` -------------------------------- ### Build and run nvm Docker image Source: https://nvm.sh Commands to build the Docker image with a specific Node version and run it in interactive or non-interactive modes. ```bash docker build -t nvmimage --build-arg NODE_VERSION=19 . ``` ```bash docker run --rm -it nvmimage root@0a6b5a237c14:/# nvm -v 0.40.6 root@0a6b5a237c14:/# node -v v19.9.0 root@0a6b5a237c14:/# npm -v 9.6.3 ``` ```bash user@host:/tmp/test $ docker run --rm -it nvmimage node -v v19.9.0 user@host:/tmp/test $ docker run --rm -it nvmimage npm -v 9.6.3 ``` -------------------------------- ### Configure shell for nvm Source: https://nvm.sh Add these lines to your shell profile (e.g., .bashrc, .profile, or .zshrc) to ensure nvm is loaded automatically on login. ```bash 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 ``` -------------------------------- ### nvm use and uninstall completion Source: https://nvm.sh Available versions for use or uninstall commands via tab completion. ```text my_alias default v10.22.0 v12.18.3 v14.8.0 ``` ```text my_alias default v10.22.0 v12.18.3 v14.8.0 ``` -------------------------------- ### Create .nvmrc configuration files Source: https://nvm.sh Commands to generate .nvmrc files for specific version requirements. ```bash $ echo "5.9" > .nvmrc $ echo "lts/*" > .nvmrc # to default to the latest LTS version $ echo "node" > .nvmrc # to default to the latest version ``` -------------------------------- ### Load nvm Configuration Source: https://nvm.sh Commands to manually load the nvm script into the current shell session. ```bash . ~/.bash_profile ``` ```bash . ~/.bashrc ``` ```bash . ~/.zshrc ``` ```bash . ~/.nvm/nvm.sh ``` -------------------------------- ### Migrate Packages Between Existing Versions Source: https://nvm.sh Reinstall global packages from a source version into the currently active version without reinstalling the Node binary. ```bash nvm use 22.22.2 nvm reinstall-packages 22.20.0 ``` -------------------------------- ### Automatic nvm switching in Fish Source: https://nvm.sh Requires the bass plugin to execute nvm commands within Fish. Configure these functions to handle directory changes. ```fish # ~/.config/fish/functions/nvm.fish function nvm bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv end # ~/.config/fish/functions/nvm_find_nvmrc.fish function nvm_find_nvmrc bass source ~/.nvm/nvm.sh --no-use ';' nvm_find_nvmrc end # ~/.config/fish/functions/load_nvm.fish function load_nvm --on-variable="PWD" set -l default_node_version (nvm version default) set -l node_version (nvm version) set -l nvmrc_path (nvm_find_nvmrc) if test -n "$nvmrc_path" set -l nvmrc_node_version (nvm version (cat $nvmrc_path)) if test "$nvmrc_node_version" = "N/A" nvm install (cat $nvmrc_path) else if test "$nvmrc_node_version" != "$node_version" nvm use $nvmrc_node_version end else if test "$node_version" != "$default_node_version" echo "Reverting to default Node version" nvm use default end end # ~/.config/fish/config.fish # You must call it on initialization or listening to directory switching won't work load_nvm > /dev/stderr ``` -------------------------------- ### Pass Authorization header to mirror Source: https://nvm.sh Set the NVM_AUTH_HEADER environment variable to include an authorization token when fetching from a mirror. ```bash NVM_AUTH_HEADER="Bearer secret-token" nvm install node ``` -------------------------------- ### Set custom NVM colors Source: https://nvm.sh Command to apply a custom color scheme to NVM output. ```bash nvm set-colors rgBcm ``` -------------------------------- ### Exit Rosetta shell and verify architecture Source: https://nvm.sh Exits the current shell and checks the system architecture to confirm native mode. ```bash $ exit $ arch arm64 ``` -------------------------------- ### Fix WSL DNS resolution Source: https://nvm.sh Commands to manually set the nameserver and disable automatic resolv.conf generation to resolve connectivity issues. ```bash sudo rm /etc/resolv.conf sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf' sudo bash -c 'echo "[network]" > /etc/wsl.conf' sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf' sudo chattr +i /etc/resolv.conf ``` -------------------------------- ### Environment variables to avoid with nvm Source: https://nvm.sh These environment variables should not be set when using nvm. ```bash $NPM_CONFIG_PREFIX $PREFIX ``` -------------------------------- ### nvm command completion Source: https://nvm.sh Available commands when pressing Tab after typing nvm. ```text alias deactivate install list-remote reinstall-packages uninstall version cache exec install-latest-npm ls run unload version-remote current help list ls-remote unalias use which ``` -------------------------------- ### Activate bash completion Source: https://nvm.sh Source the bash_completion script in your shell profile to enable tab completion. ```bash [[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion ``` -------------------------------- ### Define NVM color codes Source: https://nvm.sh Reference list for color codes used in NVM output customization. ```text r/R = red / bold red g/G = green / bold green b/B = blue / bold blue c/C = cyan / bold cyan m/M = magenta / bold magenta y/Y = yellow / bold yellow k/K = black / bold black e/W = light grey / white ``` -------------------------------- ### Automatic nvm switching in Zsh Source: https://nvm.sh Use add-zsh-hook to trigger version switching automatically when changing directories in Zsh. ```zsh # place this after nvm initialization! autoload -U add-zsh-hook load-nvmrc() { local nvmrc_path nvmrc_path="$(nvm_find_nvmrc)" if [ -n "$nvmrc_path" ]; then local nvmrc_node_version nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") if [ "$nvmrc_node_version" = "N/A" ]; then nvm install elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then nvm use fi elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then echo "Reverting to nvm default version" nvm use default fi } add-zsh-hook chpwd load-nvmrc load-nvmrc ``` -------------------------------- ### nvm alias completion Source: https://nvm.sh Available aliases or versions when using tab completion with nvm alias. ```text default iojs lts/* lts/argon lts/boron lts/carbon lts/dubnium lts/erbium node stable unstable ``` ```text v10.22.0 v12.18.3 v14.8.0 ``` -------------------------------- ### Refresh Shell Configuration Source: https://nvm.sh Commands to manually source shell configuration files to make the nvm command available in the current session. ```bash source ~/.bashrc ``` ```zsh source ~/.zshrc ``` ```ksh . ~/.profile ``` -------------------------------- ### Manage nvm aliases Source: https://nvm.sh Sets a custom alias for a specific Node.js version. ```bash nvm alias my_alias v14.4.0 ``` -------------------------------- ### Source nvm in Rosetta shell Source: https://nvm.sh Ensures nvm is available in a manually opened Rosetta terminal session. ```bash $ source "${NVM_DIR}/nvm.sh" ``` -------------------------------- ### Automatic nvm switching in Bash Source: https://nvm.sh Add this function to your .bashrc to automatically detect .nvmrc files and switch versions when using the cd command. ```bash cdnvm() { command cd "$@" || return $? nvm_path="$(nvm_find_up .nvmrc | command tr -d '\n')" # If there are no .nvmrc file, use the default nvm version if [[ ! $nvm_path = *[^[:space:]]* ]]; then declare default_version default_version="$(nvm version default)" # If there is no default version, set it to `node` # This will use the latest version on your machine if [ $default_version = 'N/A' ]; then nvm alias default node default_version=$(nvm version default) fi # If the current version is not the default version, set it to use the default version if [ "$(nvm current)" != "${default_version}" ]; then nvm use default fi elif [[ -s "${nvm_path}/.nvmrc" && -r "${nvm_path}/.nvmrc" ]]; then declare nvm_version nvm_version=$(<"${nvm_path}"/.nvmrc) declare locally_resolved_nvm_version # `nvm ls` will check all locally-available versions # If there are multiple matching versions, take the latest one # Remove the `->` and `*` characters and spaces # `locally_resolved_nvm_version` will be `N/A` if no local versions are found locally_resolved_nvm_version=$(nvm ls --no-colors "${nvm_version}" | command tail -1 | command tr -d '\->*' | command tr -d '[:space:]') # If it is not already installed, install it # `nvm install` will implicitly use the newly-installed version if [ "${locally_resolved_nvm_version}" = 'N/A' ]; then nvm install "${nvm_version}"; elif [ "$(nvm current)" != "${locally_resolved_nvm_version}" ]; then nvm use "${nvm_version}"; fi fi } alias cd='cdnvm' cdnvm "$PWD" || exit ``` -------------------------------- ### Update npm Version Source: https://nvm.sh Update to the latest supported npm version for the current Node.js environment. ```bash nvm install-latest-npm ``` -------------------------------- ### Persist custom NVM colors Source: https://nvm.sh Export the NVM_COLORS variable in your shell profile to make color changes permanent. ```bash export NVM_COLORS='cmgRY' ``` -------------------------------- ### Deactivate NVM Source: https://nvm.sh Restore the original PATH by deactivating NVM. ```bash nvm deactivate ``` -------------------------------- ### Shell setting to avoid with nvm Source: https://nvm.sh The set -e shell option can cause issues with nvm scripts. ```bash set -e ``` -------------------------------- ### Set default Node version Source: https://nvm.sh Use the 'default' alias to specify which Node version should be used in new shell sessions. ```bash nvm alias default node # this refers to the latest installed version of node nvm alias default 18 # this refers to the latest installed v18.x version of node nvm alias default 18.12 # this refers to the latest installed v18.12.x version of node ``` -------------------------------- ### Fix nvm version mismatch in vim Source: https://nvm.sh Resolves issues where vim shell commands do not reflect the current nvm-managed Node.js version. ```bash sudo chmod ugo-x /usr/libexec/path_helper ``` -------------------------------- ### Remove nvm configuration from shell profile Source: https://nvm.sh Remove these lines from your shell resource configuration file like ~/.bashrc. ```bash export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion ``` -------------------------------- ### Suppress colorized output Source: https://nvm.sh Disable color output using the --no-colors flag or by setting the TERM environment variable. ```bash nvm ls --no-colors nvm help --no-colors TERM=dumb nvm ls ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.