mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-01-12 18:27:17 +08:00
Compare commits
2 Commits
awk
...
49951f31ca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49951f31ca | ||
|
|
e87ec0c013 |
59
README.md
59
README.md
@@ -19,7 +19,6 @@
|
|||||||
- [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)
|
- [Installing in Docker](#installing-in-docker)
|
||||||
- [Installing in Docker for CICD-Jobs](#installing-in-docker-for-cicd-jobs)
|
|
||||||
- [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)
|
||||||
@@ -155,62 +154,6 @@ RUN echo node > .nvmrc
|
|||||||
RUN nvm install
|
RUN nvm install
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Installing in Docker for CICD-Jobs
|
|
||||||
|
|
||||||
More robust, works in CI/CD-Jobs. Can be run in interactive and non-interactive containers.
|
|
||||||
See https://github.com/nvm-sh/nvm/issues/3531.
|
|
||||||
|
|
||||||
```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.1/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"]
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
This example defaults to installation of nodejs version 20.x.y. Optionally you can easily override the version with docker build args like:
|
|
||||||
```
|
|
||||||
docker build -t nvmimage --build-arg NODE_VERSION=19 .
|
|
||||||
```
|
|
||||||
|
|
||||||
After creation of the image you can start container interactively and run commands, for example:
|
|
||||||
```
|
|
||||||
docker run --rm -it nvmimage
|
|
||||||
|
|
||||||
root@0a6b5a237c14:/# nvm -v
|
|
||||||
0.40.1
|
|
||||||
|
|
||||||
root@0a6b5a237c14:/# node -v
|
|
||||||
v19.9.0
|
|
||||||
|
|
||||||
root@0a6b5a237c14:/# npm -v
|
|
||||||
9.6.3
|
|
||||||
```
|
|
||||||
|
|
||||||
Noninteractive example:
|
|
||||||
```
|
|
||||||
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
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 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.
|
||||||
@@ -890,7 +833,7 @@ my_alias default v10.22.0 v12.18.3 v14.8.0
|
|||||||
|
|
||||||
## Compatibility Issues
|
## Compatibility Issues
|
||||||
|
|
||||||
`nvm` will encounter some issues if you have some non-default settings set. (see [#606](https://github.com/nvm-sh/nvm/issues/606))
|
`nvm` will encounter some issues if you have some non-default settings set. (see [#606](https://github.com/creationix/nvm/issues/606))
|
||||||
The following are known to cause issues:
|
The following are known to cause issues:
|
||||||
|
|
||||||
Inside `~/.npmrc`:
|
Inside `~/.npmrc`:
|
||||||
|
|||||||
2
nvm.sh
2
nvm.sh
@@ -2740,7 +2740,7 @@ nvm_npm_global_modules() {
|
|||||||
NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed -e '1d' -e '/UNMET PEER DEPENDENCY/d')
|
NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed -e '1d' -e '/UNMET PEER DEPENDENCY/d')
|
||||||
|
|
||||||
local INSTALLS
|
local INSTALLS
|
||||||
INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' -e '/^corepack@[^ ]*.*$/ d' | command xargs)
|
INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs)
|
||||||
|
|
||||||
local LINKS
|
local LINKS
|
||||||
LINKS="$(nvm_echo "${NPMLIST}" | command sed -n 's/.* -> \(.*\)/\1/ p')"
|
LINKS="$(nvm_echo "${NPMLIST}" | command sed -n 's/.* -> \(.*\)/\1/ p')"
|
||||||
|
|||||||
@@ -45,9 +45,9 @@
|
|||||||
"dockerfile_lint": "^0.3.4",
|
"dockerfile_lint": "^0.3.4",
|
||||||
"doctoc": "^2.2.1",
|
"doctoc": "^2.2.1",
|
||||||
"eclint": "^2.8.1",
|
"eclint": "^2.8.1",
|
||||||
"markdown-link-check": "^3.13.7",
|
"markdown-link-check": "^3.13.6",
|
||||||
"replace": "^1.2.2",
|
"replace": "^1.2.2",
|
||||||
"semver": "^7.7.1",
|
"semver": "^7.6.3",
|
||||||
"urchin": "^0.0.5"
|
"urchin": "^0.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,11 @@ nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_T
|
|||||||
# Remove the stuff we're clobbering.
|
# Remove the stuff we're clobbering.
|
||||||
[ -e ../../$NVM_TEST_VERSION ] && rm -R ../../$NVM_TEST_VERSION
|
[ -e ../../$NVM_TEST_VERSION ] && rm -R ../../$NVM_TEST_VERSION
|
||||||
|
|
||||||
# Install from source with 2 make jobs (and swapped arg order)
|
# Speed up test for non-CI environment which may have more CPU threads
|
||||||
nvm install -j 2 -s $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
|
[ -z "${CI-}"] && nvm_get_make_jobs
|
||||||
|
|
||||||
|
# Install from source with multiple make jobs (and swapped arg order)
|
||||||
|
nvm install -j ${NVM_MAKE_JOBS-:2} -s $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
|
||||||
|
|
||||||
# Check
|
# Check
|
||||||
[ -d ../../$NVM_TEST_VERSION ]
|
[ -d ../../$NVM_TEST_VERSION ]
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ EXPECTED_PACKAGES_INSTALL="autoprefixer bower david@11 grunt-cli grunth-cli http
|
|||||||
echo "$EXPECTED_PACKAGES_INSTALL" | sed -e 's/test-npmlink //' | xargs npm install -g --quiet
|
echo "$EXPECTED_PACKAGES_INSTALL" | sed -e 's/test-npmlink //' | xargs npm install -g --quiet
|
||||||
|
|
||||||
get_packages() {
|
get_packages() {
|
||||||
npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' -e '/^corepack$/ d' | xargs
|
npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | xargs
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm use 0.10.29
|
nvm use 0.10.29
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ die () { echo "$@" ; exit 1; }
|
|||||||
\. ../../../nvm.sh
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
get_packages() {
|
get_packages() {
|
||||||
npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' -e '/^corepack$/ d' | xargs
|
npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | xargs
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm use 4.7.2
|
nvm use 4.7.2
|
||||||
@@ -14,14 +14,5 @@ ORIGINAL_PACKAGES=$(get_packages)
|
|||||||
nvm reinstall-packages 4.7.1
|
nvm reinstall-packages 4.7.1
|
||||||
FINAL_PACKAGES=$(get_packages)
|
FINAL_PACKAGES=$(get_packages)
|
||||||
|
|
||||||
[ -z "${ORIGINAL_PACKAGES}" ] || die "v4: original packages were not empty: ${ORIGINAL_PACKAGES}"
|
[ -z "${ORIGINAL_PACKAGES}" ] || die "original packages were not empty: ${ORIGINAL_PACKAGES}"
|
||||||
[ -z "${FINAL_PACKAGES}" ] || die "v4: final packages were not empty: ${FINAL_PACKAGES}"
|
[ -z "${FINAL_PACKAGES}" ] || die "final packages were not empty: ${FINAL_PACKAGES}"
|
||||||
|
|
||||||
nvm use 23.8.20
|
|
||||||
ORIGINAL_PACKAGES=$(get_packages)
|
|
||||||
|
|
||||||
nvm reinstall-packages 23.8.0
|
|
||||||
FINAL_PACKAGES=$(get_packages)
|
|
||||||
|
|
||||||
[ -z "${ORIGINAL_PACKAGES}" ] || die "v23: original packages were not empty: ${ORIGINAL_PACKAGES}"
|
|
||||||
[ -z "${FINAL_PACKAGES}" ] || die "v23: final packages were not empty: ${FINAL_PACKAGES}"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user