mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-08-17 19:13:43 +00:00
Compare commits
13 Commits
fb60801d67
...
d61c90d529
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d61c90d529 | ||
![]() |
b4ee18be6a | ||
![]() |
3b811237cb | ||
![]() |
ad4fa37deb | ||
![]() |
d956279e5a | ||
![]() |
c18cbf4d25 | ||
![]() |
b77fcec399 | ||
![]() |
287d535f2c | ||
![]() |
572c757f6d | ||
![]() |
1d39e35bd3 | ||
![]() |
19f452ba0f | ||
![]() |
b9b0ea8020 | ||
![]() |
dae1427f7e |
5
.github/workflows/latest-npm.yml
vendored
5
.github/workflows/latest-npm.yml
vendored
@ -37,6 +37,11 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
|
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
|
||||||
include:
|
include:
|
||||||
|
- node-version: "21"
|
||||||
|
- node-version: "20.5"
|
||||||
|
- node-version: "20.4"
|
||||||
|
- node-version: "14.17"
|
||||||
|
- node-version: "14.16"
|
||||||
- node-version: "9.2"
|
- node-version: "9.2"
|
||||||
- node-version: "9.1"
|
- node-version: "9.1"
|
||||||
- node-version: "9.0"
|
- node-version: "9.0"
|
||||||
|
3
.github/workflows/toc.yml
vendored
3
.github/workflows/toc.yml
vendored
@ -20,6 +20,7 @@ jobs:
|
|||||||
allowed-endpoints:
|
allowed-endpoints:
|
||||||
github.com:443
|
github.com:443
|
||||||
registry.npmjs.org:443
|
registry.npmjs.org:443
|
||||||
|
api.github.com:443
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# https://github.com/actions/checkout/issues/217#issue-599945005
|
# https://github.com/actions/checkout/issues/217#issue-599945005
|
||||||
@ -30,7 +31,7 @@ jobs:
|
|||||||
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: 'lts/*'
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run doctoc
|
- run: npm run doctoc
|
||||||
- name: commit changes
|
- name: commit changes
|
||||||
|
18
Dockerfile
18
Dockerfile
@ -91,16 +91,20 @@ RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
|
|||||||
# Switch to user "nvm" from now
|
# Switch to user "nvm" from now
|
||||||
USER nvm
|
USER nvm
|
||||||
|
|
||||||
|
# Create a script file sourced by both interactive and non-interactive bash shells
|
||||||
|
ENV BASH_ENV /home/nvm/.bash_env
|
||||||
|
RUN touch "$BASH_ENV"
|
||||||
|
RUN echo '. "$BASH_ENV"' >> "$HOME/.bashrc"
|
||||||
|
|
||||||
# nvm
|
# nvm
|
||||||
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$HOME/.bashrc"
|
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$BASH_ENV"
|
||||||
RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$HOME/.bashrc"
|
RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$BASH_ENV"
|
||||||
RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$HOME/.bashrc"
|
RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$BASH_ENV"
|
||||||
|
|
||||||
# nodejs and tools
|
# nodejs and tools
|
||||||
RUN bash -c 'source $HOME/.nvm/nvm.sh && \
|
RUN nvm install node
|
||||||
nvm install node && \
|
RUN npm install -g doctoc urchin eclint dockerfile_lint
|
||||||
npm install -g doctoc urchin eclint dockerfile_lint && \
|
RUN npm install --prefix "$HOME/.nvm/"
|
||||||
npm install --prefix "$HOME/.nvm/"'
|
|
||||||
|
|
||||||
# Set WORKDIR to nvm directory
|
# Set WORKDIR to nvm directory
|
||||||
WORKDIR /home/nvm/.nvm
|
WORKDIR /home/nvm/.nvm
|
||||||
|
26
README.md
26
README.md
@ -18,6 +18,7 @@
|
|||||||
- [Installing and Updating](#installing-and-updating)
|
- [Installing and Updating](#installing-and-updating)
|
||||||
- [Install & Update Script](#install--update-script)
|
- [Install & Update Script](#install--update-script)
|
||||||
- [Additional Notes](#additional-notes)
|
- [Additional Notes](#additional-notes)
|
||||||
|
- [Installing in Docker](#installing-in-docker)
|
||||||
- [Troubleshooting on Linux](#troubleshooting-on-linux)
|
- [Troubleshooting on Linux](#troubleshooting-on-linux)
|
||||||
- [Troubleshooting on macOS](#troubleshooting-on-macos)
|
- [Troubleshooting on macOS](#troubleshooting-on-macos)
|
||||||
- [Ansible](#ansible)
|
- [Ansible](#ansible)
|
||||||
@ -129,6 +130,25 @@ Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not conta
|
|||||||
|
|
||||||
- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash'`
|
- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash'`
|
||||||
|
|
||||||
|
#### Installing in Docker
|
||||||
|
|
||||||
|
When invoking bash as a non-interactive shell, like in a Docker container, none of the regular profile files are sourced. In order to use `nvm`, `node`, and `npm` like normal, you can instead specify the special `BASH_ENV` variable, which bash sources when invoked non-interactively.
|
||||||
|
|
||||||
|
```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/user/.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.39.2/install.sh | PROFILE="${BASH_ENV}" bash
|
||||||
|
RUN echo node > .nvmrc
|
||||||
|
RUN nvm install
|
||||||
|
```
|
||||||
|
|
||||||
#### Troubleshooting on Linux
|
#### Troubleshooting on Linux
|
||||||
|
|
||||||
On Linux, after running the install script, if you get `nvm: command not found` or see no feedback from your terminal after you type `command -v nvm`, simply close your current terminal, open a new terminal, and try verifying again.
|
On Linux, after running the install script, if you get `nvm: command not found` or see no feedback from your terminal after you type `command -v nvm`, simply close your current terminal, open a new terminal, and try verifying again.
|
||||||
@ -207,7 +227,7 @@ If you're running a system without prepackaged binary available, which means you
|
|||||||
- [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell
|
- [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell
|
||||||
- [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup
|
- [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup
|
||||||
- [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell
|
- [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell
|
||||||
- [fnm](https://github.com/fisherman/fnm) - [fisherman](https://github.com/fisherman/fisherman)-based version manager for fish
|
- [nvm.fish](https://github.com/jorgebucaran/nvm.fish) - The Node.js version manager you'll adore, crafted just for Fish
|
||||||
- [fish-nvm](https://github.com/FabioAntunes/fish-nvm) - Wrapper around nvm for fish, delays sourcing nvm until it's actually used.
|
- [fish-nvm](https://github.com/FabioAntunes/fish-nvm) - Wrapper around nvm for fish, delays sourcing nvm until it's actually used.
|
||||||
|
|
||||||
**Note:** We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need [patches](https://www.freshports.org/www/node/files/patch-deps_v8_src_base_platform_platform-posix.cc); see the issue ticket:
|
**Note:** We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need [patches](https://www.freshports.org/www/node/files/patch-deps_v8_src_base_platform_platform-posix.cc); see the issue ticket:
|
||||||
@ -588,9 +608,7 @@ Run [`npx nvmrc`](https://npmjs.com/nvmrc) to validate an `.nvmrc` file. If that
|
|||||||
|
|
||||||
### Deeper Shell Integration
|
### Deeper Shell Integration
|
||||||
|
|
||||||
You can use [`avn`](https://github.com/wbyoung/avn) to deeply integrate into your shell and automatically invoke `nvm` when changing directories. `avn` is **not** supported by the `nvm` maintainers. Please [report issues to the `avn` team](https://github.com/wbyoung/avn/issues/new).
|
You can use [`nvshim`](https://github.com/iamogbz/nvshim) to shim the `node`, `npm`, and `npx` bins to automatically use the `nvm` config in the current directory. `nvshim` is **not** supported by the `nvm` maintainers. Please [report issues to the `nvshim` team](https://github.com/iamogbz/nvshim/issues/new).
|
||||||
|
|
||||||
You can also use [`nvshim`](https://github.com/iamogbz/nvshim) to shim the `node`, `npm`, and `npx` bins to automatically use the `nvm` config in the current directory. `nvshim` is **not** supported by the `nvm` maintainers. Please [report issues to the `nvshim` team](https://github.com/iamogbz/nvshim/issues/new).
|
|
||||||
|
|
||||||
If you prefer a lighter-weight solution, the recipes below have been contributed by `nvm` users. They are **not** supported by the `nvm` maintainers. We are, however, accepting pull requests for more examples.
|
If you prefer a lighter-weight solution, the recipes below have been contributed by `nvm` users. They are **not** supported by the `nvm` maintainers. We are, however, accepting pull requests for more examples.
|
||||||
|
|
||||||
|
5
nvm-exec
5
nvm-exec
@ -1,6 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
SOURCE=${BASH_SOURCE[0]}
|
||||||
|
test -L "$SOURCE" && command cd "$( dirname "$SOURCE" )" && \
|
||||||
|
SOURCE=$(readlink "$SOURCE")
|
||||||
|
DIR="$(command cd "$( dirname "$SOURCE" )" && pwd )"
|
||||||
|
|
||||||
unset NVM_CD_FLAGS
|
unset NVM_CD_FLAGS
|
||||||
|
|
||||||
|
40
nvm.sh
40
nvm.sh
@ -354,6 +354,21 @@ nvm_install_latest_npm() {
|
|||||||
if [ $NVM_IS_19_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 20.5.0; then
|
if [ $NVM_IS_19_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 20.5.0; then
|
||||||
NVM_IS_20_5_OR_ABOVE=1
|
NVM_IS_20_5_OR_ABOVE=1
|
||||||
fi
|
fi
|
||||||
|
local NVM_IS_20_17_or_ABOVE
|
||||||
|
NVM_IS_20_17_or_ABOVE=0
|
||||||
|
if [ $NVM_IS_20_5_OR_ABOVE -eq 1 ] && nvm_version_greater 20.17.0 "${NODE_VERSION}"; then
|
||||||
|
NVM_IS_20_17_or_ABOVE=1
|
||||||
|
fi
|
||||||
|
local NVM_IS_21_OR_ABOVE
|
||||||
|
NVM_IS_21_OR_ABOVE=0
|
||||||
|
if [ $NVM_IS_20_17_or_ABOVE -eq 1 ] && nvm_version_greater 21.0.0 "${NODE_VERSION}"; then
|
||||||
|
NVM_IS_21_OR_ABOVE=1
|
||||||
|
fi
|
||||||
|
local NVM_IS_22_9_OR_ABOVE
|
||||||
|
NVM_IS_22_9_OR_ABOVE=0
|
||||||
|
if [ $NVM_IS_21_OR_ABOVE -eq 1 ] && nvm_version_greater 22.9.0 "${NODE_VERSION}"; then
|
||||||
|
NVM_IS_22_9_OR_ABOVE=1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || {
|
if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || {
|
||||||
[ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \
|
[ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \
|
||||||
@ -399,8 +414,15 @@ nvm_install_latest_npm() {
|
|||||||
[ $NVM_IS_18_17_OR_ABOVE -eq 0 ] \
|
[ $NVM_IS_18_17_OR_ABOVE -eq 0 ] \
|
||||||
|| { [ $NVM_IS_19_OR_ABOVE -eq 1 ] && [ $NVM_IS_20_5_OR_ABOVE -eq 0 ]; } \
|
|| { [ $NVM_IS_19_OR_ABOVE -eq 1 ] && [ $NVM_IS_20_5_OR_ABOVE -eq 0 ]; } \
|
||||||
; then
|
; then
|
||||||
|
# TODO: 10.8.3 can run on 16.20.2?? https://github.com/nodejs/Release/issues/884#issuecomment-2558077691
|
||||||
nvm_echo '* `npm` `v9.x` is the last version that works on `node` `< v18.17`, `v19`, or `v20.0` - `v20.4`'
|
nvm_echo '* `npm` `v9.x` is the last version that works on `node` `< v18.17`, `v19`, or `v20.0` - `v20.4`'
|
||||||
$NVM_NPM_CMD install -g npm@9
|
$NVM_NPM_CMD install -g npm@9
|
||||||
|
elif \
|
||||||
|
[ $NVM_IS_20_17_or_ABOVE -eq 0 ] \
|
||||||
|
|| { [ $NVM_IS_21_OR_ABOVE -eq 1 ] && [ $NVM_IS_22_9_OR_ABOVE -eq 0 ]; } \
|
||||||
|
; then
|
||||||
|
nvm_echo '* `npm` `v10.x` is the last version that works on `node` `< v20.17`, `v21`, or `v22.0` - `v22.8`'
|
||||||
|
$NVM_NPM_CMD install -g npm@10
|
||||||
else
|
else
|
||||||
nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!'
|
nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!'
|
||||||
$NVM_NPM_CMD install -g npm
|
$NVM_NPM_CMD install -g npm
|
||||||
@ -422,8 +444,7 @@ fi
|
|||||||
if [ -z "${NVM_DIR-}" ]; then
|
if [ -z "${NVM_DIR-}" ]; then
|
||||||
# shellcheck disable=SC2128
|
# shellcheck disable=SC2128
|
||||||
if [ -n "${BASH_SOURCE-}" ]; then
|
if [ -n "${BASH_SOURCE-}" ]; then
|
||||||
# shellcheck disable=SC2169,SC3054
|
NVM_SCRIPT_SOURCE="${BASH_SOURCE}"
|
||||||
NVM_SCRIPT_SOURCE="${BASH_SOURCE[0]}"
|
|
||||||
fi
|
fi
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" >/dev/null && \pwd)"
|
NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" >/dev/null && \pwd)"
|
||||||
@ -1242,10 +1263,9 @@ nvm_list_aliases() {
|
|||||||
if [ -n "${LTS_ALIAS}" ]; then
|
if [ -n "${LTS_ALIAS}" ]; then
|
||||||
nvm_echo "${LTS_ALIAS}"
|
nvm_echo "${LTS_ALIAS}"
|
||||||
fi
|
fi
|
||||||
} &
|
}
|
||||||
done
|
done
|
||||||
wait
|
)
|
||||||
) | command sort
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2508,12 +2528,12 @@ nvm_extract_tarball() {
|
|||||||
|
|
||||||
if [ "${NVM_OS}" = 'openbsd' ]; then
|
if [ "${NVM_OS}" = 'openbsd' ]; then
|
||||||
if [ "${tar_compression_flag}" = 'J' ]; then
|
if [ "${tar_compression_flag}" = 'J' ]; then
|
||||||
command xzcat "${TARBALL}" | "${tar}" -xf - -C "${TMPDIR}" -s '/[^\/]*\///' || return 1
|
command xzcat "${TARBALL}" | "${tar}" --no-same-owner -xf - -C "${TMPDIR}" -s '/[^\/]*\///' || return 1
|
||||||
else
|
else
|
||||||
command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" -s '/[^\/]*\///' || return 1
|
command "${tar}" --no-same-owner -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" -s '/[^\/]*\///' || return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 || return 1
|
command "${tar}" --no-same-owner -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 || return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4054,7 +4074,9 @@ nvm() {
|
|||||||
nvm_echo "Running node ${VERSION}$(nvm use --silent "${VERSION}" && nvm_print_npm_version)"
|
nvm_echo "Running node ${VERSION}$(nvm use --silent "${VERSION}" && nvm_print_npm_version)"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
NODE_VERSION="${VERSION}" "${NVM_DIR}/nvm-exec" "$@"
|
NVM_EXEC="$NVM_DIR/nvm-exec"
|
||||||
|
test ! -f "$NVM_EXEC" && NVM_EXEC="$(dirname "${BASH_SOURCE[0]-}")/nvm-exec"
|
||||||
|
NODE_VERSION="$VERSION" "$NVM_EXEC" "$@"
|
||||||
;;
|
;;
|
||||||
"ls" | "list")
|
"ls" | "list")
|
||||||
local PATTERN
|
local PATTERN
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
INSTPATH="$(mktemp -p "$(pwd)" -d)"
|
||||||
|
trap 'test ! -z "${INSTPATH-}" && test -d "$INSTPATH" && rm -rf "$INSTPATH"' EXIT
|
||||||
|
declare -x NVM_DIR=$INSTPATH
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
nvm install --lts || die 'nvm install --lts failed'
|
||||||
|
nvm exec --lts npm --version || die "`nvm exec` failed to run"
|
||||||
|
declare -x NODE_VERSION="$(nvm exec --lts --silent node --version)"
|
||||||
|
|
||||||
|
ln -s ../../../../nvm-exec "$INSTPATH/nvm-exec" || die "failed to create a symlink to $INSTPATH/"
|
||||||
|
"$INSTPATH/nvm-exec" npm ls > /dev/null || die "`nvm exec` failed to run using nvm-exec helper"
|
||||||
|
|
0
test/slow/nvm uninstall/Running 'nvm uninstall' with incorrect file permissions fails nicely
Executable file → Normal file
0
test/slow/nvm uninstall/Running 'nvm uninstall' with incorrect file permissions fails nicely
Executable file → Normal file
Loading…
x
Reference in New Issue
Block a user