Showing preview only (1,161K chars total). Download the full file or copy to clipboard to get everything.
Repository: nvm-sh/nvm
Branch: master
Commit: 6b307d0c7504
Files: 367
Total size: 1.0 MB
Directory structure:
gitextract_ttgsrgia/
├── .dockerignore
├── .editorconfig
├── .gitattributes
├── .github/
│ ├── FUNDING.yml
│ ├── INCIDENT_RESPONSE_PLAN.md
│ ├── ISSUE_TEMPLATE/
│ │ ├── config.yml
│ │ └── issue_template.md
│ ├── SECURITY.md
│ ├── THREAT_MODEL.md
│ └── workflows/
│ ├── codeql-analysis.yml
│ ├── latest-npm.yml
│ ├── lint.yml
│ ├── nodejs-org.yml
│ ├── nvm-install-test.yml
│ ├── rebase.yml
│ ├── release.yml
│ ├── require-allow-edits.yml
│ ├── shellcheck.yml
│ ├── tests-fast.yml
│ ├── tests-installation-iojs.yml
│ ├── tests-installation-node.yml
│ ├── tests-xenial.yml
│ ├── tests.yml
│ ├── toc.yml
│ └── windows-npm.yml
├── .gitignore
├── .gitmodules
├── .mailmap
├── .npmrc
├── AGENTS.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Dockerfile
├── GOVERNANCE.md
├── LICENSE.md
├── Makefile
├── PROJECT_CHARTER.md
├── README.md
├── ROADMAP.md
├── bash_completion
├── install.sh
├── nvm-exec
├── nvm.sh
├── package.json
├── rename_test.sh
├── test/
│ ├── common.sh
│ ├── fast/
│ │ ├── Aliases/
│ │ │ ├── 'nvm alias' should ignore leading blank lines in the file
│ │ │ ├── 'nvm alias' should not accept aliases with a hash
│ │ │ ├── 'nvm alias' should not accept aliases with slashes
│ │ │ ├── 'nvm unalias' should accept aliases when they shadow a built-in alias
│ │ │ ├── 'nvm unalias' should not accept aliases with names equal to built-in alias
│ │ │ ├── 'nvm unalias' should not accept aliases with slashes
│ │ │ ├── Running 'nvm alias ˂aliasname˃ ˂target˃' again should change the target
│ │ │ ├── Running 'nvm alias ˂aliasname˃' should list but one alias
│ │ │ ├── Running 'nvm alias' lists implicit aliases when they do not exist
│ │ │ ├── Running 'nvm alias' lists manual aliases instead of implicit aliases when present
│ │ │ ├── Running 'nvm alias' should list all aliases
│ │ │ ├── circular/
│ │ │ │ ├── nvm_resolve_alias
│ │ │ │ ├── nvm_resolve_local_alias
│ │ │ │ ├── setup
│ │ │ │ └── teardown
│ │ │ ├── lts/
│ │ │ │ ├── 'nvm alias' should ensure LTS alias dir exists
│ │ │ │ ├── setup_dir
│ │ │ │ └── teardown_dir
│ │ │ ├── nvm_ensure_default_set
│ │ │ ├── nvm_list_aliases calls nvm_get_colors
│ │ │ ├── nvm_list_aliases works with LTS aliases
│ │ │ ├── nvm_list_aliases works with no LTS aliases present
│ │ │ ├── nvm_print_alias_path calls nvm_get_colors
│ │ │ ├── nvm_print_formatted_alias calls nvm_get_colors
│ │ │ ├── nvm_resolve_alias
│ │ │ ├── nvm_resolve_local_alias
│ │ │ ├── setup
│ │ │ └── teardown
│ │ ├── Listing paths/
│ │ │ ├── Running 'nvm which 0.0.2' should display only version 0.0.2
│ │ │ ├── Running 'nvm which foo' should return a nonzero exit code when not found
│ │ │ ├── Running 'nvm which' should respect alias pointing to system
│ │ │ └── teardown
│ │ ├── Listing versions/
│ │ │ ├── Running 'nvm ls --no-alias' does not call into nvm_alias
│ │ │ ├── Running 'nvm ls --no-alias' with a pattern errors
│ │ │ ├── Running 'nvm ls 0.0.2' should display only version 0.0.2
│ │ │ ├── Running 'nvm ls 0.2' should display only 0.2.x versions
│ │ │ ├── Running 'nvm ls default' should show system version when available
│ │ │ ├── Running 'nvm ls foo' should return a nonzero exit code when not found
│ │ │ ├── Running 'nvm ls io' should return NA
│ │ │ ├── Running 'nvm ls node_' should return a nonzero exit code when not found
│ │ │ ├── Running 'nvm ls stable' and 'nvm ls unstable' should return the appropriate implicit alias
│ │ │ ├── Running 'nvm ls system' should include 'system' when appropriate
│ │ │ ├── Running 'nvm ls' calls into nvm_alias
│ │ │ ├── Running 'nvm ls' should display all installed versions
│ │ │ ├── Running 'nvm ls' should filter out '.nvm'
│ │ │ ├── Running 'nvm ls' should filter out 'versions'
│ │ │ ├── Running 'nvm ls' should include 'system' when appropriate
│ │ │ ├── Running 'nvm ls' should list versions in the 'versions' directory
│ │ │ ├── Running 'nvm ls' should not show a trailing slash
│ │ │ ├── Running 'nvm ls' with node-like versioning vx.x.x should only list a matched version
│ │ │ ├── Running 'nvm ls' with nounset should not fail
│ │ │ ├── Using a nonstandard IFS should not break
│ │ │ └── teardown
│ │ ├── Running 'nvm alias' should create a file in the alias directory
│ │ ├── Running 'nvm current' should display current nvm environment
│ │ ├── Running 'nvm deactivate' should unset the nvm environment variables
│ │ ├── Running 'nvm install' with '--reinstall-packages-from' requires a valid version
│ │ ├── Running 'nvm install' with an invalid version fails nicely
│ │ ├── Running 'nvm unalias' should remove the alias file
│ │ ├── Running 'nvm uninstall' should remove the appropriate directory
│ │ ├── Running 'nvm uninstall' with an inferred version shows the inferred message
│ │ ├── Running 'nvm uninstall' with an uninstalled version shows the requested version
│ │ ├── Running 'nvm uninstall' with incorrect file permissions fails nicely
│ │ ├── Running 'nvm unload' should unset all function and variables
│ │ ├── Running 'nvm use foo' where 'foo' is circular aborts
│ │ ├── Running 'nvm use iojs' uses latest io.js version
│ │ ├── Running 'nvm use system' should work as expected
│ │ ├── Running 'nvm use x' should create and change the 'current' symlink
│ │ ├── Running 'nvm use x' should not create the 'current' symlink if $NVM_SYMLINK_CURRENT is false
│ │ ├── Running 'nvm use' should drop CR char automatically
│ │ ├── Running 'nvm use' should respect alias pointing to system
│ │ ├── Running 'nvm use' should respect system in .nvmrc
│ │ ├── Running 'nvm-exec' should display required node version
│ │ ├── Set Colors/
│ │ │ ├── nvm_echo_with_colors
│ │ │ ├── nvm_err_with_colors
│ │ │ ├── nvm_print_default_alias calls nvm_get_colors
│ │ │ └── nvm_print_versions calls nvm_get_colors
│ │ ├── Sourcing nvm.sh should make the nvm command available
│ │ ├── Sourcing nvm.sh should not modify parameters of caller
│ │ ├── Unit tests/
│ │ │ ├── Running 'nvm install --save' works as expected'
│ │ │ ├── Running 'nvm use --save' works as expected'
│ │ │ ├── Running 'nvm use --save' works with a .nvmrc in the parent dir
│ │ │ ├── Running 'nvm use --silent --save' doesn't output anything
│ │ │ ├── mocks/
│ │ │ │ ├── LTS_names.txt
│ │ │ │ ├── iojs.org-dist-index.tab
│ │ │ │ ├── lts-star.txt
│ │ │ │ ├── nodejs.org-dist-index.tab
│ │ │ │ ├── nodejs.org-download-nightly-index.tab
│ │ │ │ ├── nvm ls-remote iojs.txt
│ │ │ │ ├── nvm ls-remote lts.txt
│ │ │ │ ├── nvm ls-remote node.txt
│ │ │ │ ├── nvm ls-remote.txt
│ │ │ │ ├── nvm_ls_remote LTS argon.txt
│ │ │ │ ├── nvm_ls_remote LTS nightly argon.txt
│ │ │ │ ├── nvm_ls_remote LTS nightly.txt
│ │ │ │ ├── nvm_ls_remote LTS.txt
│ │ │ │ ├── nvm_ls_remote nightly.txt
│ │ │ │ ├── nvm_ls_remote stable nightly.txt
│ │ │ │ ├── nvm_ls_remote stable.txt
│ │ │ │ ├── nvm_ls_remote.txt
│ │ │ │ ├── nvm_ls_remote_iojs.txt
│ │ │ │ ├── nvm_make_alias LTS alias calls.txt
│ │ │ │ ├── nvm_print_implicit_alias remote stable nightly.txt
│ │ │ │ ├── nvm_print_implicit_alias remote stable.txt
│ │ │ │ └── project_dirs/
│ │ │ │ ├── nested-both/
│ │ │ │ │ ├── a/
│ │ │ │ │ │ └── b/
│ │ │ │ │ │ └── c/
│ │ │ │ │ │ └── d/
│ │ │ │ │ │ └── .gitkeep
│ │ │ │ │ └── package.json
│ │ │ │ ├── nested-n_m/
│ │ │ │ │ └── a/
│ │ │ │ │ └── b/
│ │ │ │ │ └── c/
│ │ │ │ │ └── d/
│ │ │ │ │ └── .gitkeep
│ │ │ │ ├── nested-pkg/
│ │ │ │ │ ├── a/
│ │ │ │ │ │ └── b/
│ │ │ │ │ │ └── c/
│ │ │ │ │ │ └── d/
│ │ │ │ │ │ └── .gitkeep
│ │ │ │ │ └── package.json
│ │ │ │ ├── no-nesting-both/
│ │ │ │ │ └── package.json
│ │ │ │ └── no-nesting-pkg/
│ │ │ │ └── package.json
│ │ │ ├── nvm install --offline
│ │ │ ├── nvm install -b
│ │ │ ├── nvm install with nonlowercase LTS name
│ │ │ ├── nvm ls-remote
│ │ │ ├── nvm set_colors
│ │ │ ├── nvm version-remote
│ │ │ ├── nvm_add_iojs_prefix
│ │ │ ├── nvm_alias
│ │ │ ├── nvm_alias LTS-N
│ │ │ ├── nvm_alias handles comments
│ │ │ ├── nvm_alias_path
│ │ │ ├── nvm_change_path
│ │ │ ├── nvm_check_for_help
│ │ │ ├── nvm_clang_version
│ │ │ ├── nvm_command_info
│ │ │ ├── nvm_compare_checksum
│ │ │ ├── nvm_compute_checksum
│ │ │ ├── nvm_curl_libz_support
│ │ │ ├── nvm_curl_use_compression
│ │ │ ├── nvm_curl_version
│ │ │ ├── nvm_die_on_prefix
│ │ │ ├── nvm_download
│ │ │ ├── nvm_download_artifact
│ │ │ ├── nvm_ensure_default_set
│ │ │ ├── nvm_ensure_version_installed
│ │ │ ├── nvm_ensure_version_prefix
│ │ │ ├── nvm_extract_tarball
│ │ │ ├── nvm_find_project_dir
│ │ │ ├── nvm_find_up
│ │ │ ├── nvm_format_version
│ │ │ ├── nvm_get_arch
│ │ │ ├── nvm_get_arch_unofficial
│ │ │ ├── nvm_get_artifact_compression
│ │ │ ├── nvm_get_checksum
│ │ │ ├── nvm_get_checksum_alg
│ │ │ ├── nvm_get_checksum_binary
│ │ │ ├── nvm_get_colors
│ │ │ ├── nvm_get_default_packages
│ │ │ ├── nvm_get_default_packages mawk compat
│ │ │ ├── nvm_get_download_slug
│ │ │ ├── nvm_get_latest missing curl or wget
│ │ │ ├── nvm_get_minor_version
│ │ │ ├── nvm_get_mirror
│ │ │ ├── nvm_has
│ │ │ ├── nvm_has_colors
│ │ │ ├── nvm_has_non_aliased
│ │ │ ├── nvm_has_solaris_binary
│ │ │ ├── nvm_has_system_iojs
│ │ │ ├── nvm_has_system_node
│ │ │ ├── nvm_install_binary_extract
│ │ │ ├── nvm_install_binary_nosource
│ │ │ ├── nvm_install_latest_npm
│ │ │ ├── nvm_install_no_progress_bar
│ │ │ ├── nvm_install_source SHELL override
│ │ │ ├── nvm_iojs_prefix
│ │ │ ├── nvm_iojs_version_has_solaris_binary
│ │ │ ├── nvm_is_alias
│ │ │ ├── nvm_is_iojs_version
│ │ │ ├── nvm_is_merged_node_version
│ │ │ ├── nvm_is_natural_num
│ │ │ ├── nvm_is_valid_version
│ │ │ ├── nvm_is_version_installed
│ │ │ ├── nvm_ls handles hash in pattern
│ │ │ ├── nvm_ls_current
│ │ │ ├── nvm_ls_remote
│ │ │ ├── nvm_ls_remote LTS aliases
│ │ │ ├── nvm_ls_remote nightly
│ │ │ ├── nvm_ls_remote_iojs
│ │ │ ├── nvm_make_alias
│ │ │ ├── nvm_node_prefix
│ │ │ ├── nvm_node_version_has_solaris_binary
│ │ │ ├── nvm_normalize_lts
│ │ │ ├── nvm_num_version_groups
│ │ │ ├── nvm_offline_version
│ │ │ ├── nvm_print_alias_path
│ │ │ ├── nvm_print_color_code
│ │ │ ├── nvm_print_default_alias
│ │ │ ├── nvm_print_implicit_alias errors
│ │ │ ├── nvm_print_implicit_alias success
│ │ │ ├── nvm_print_npm_version
│ │ │ ├── nvm_process_nvmrc
│ │ │ ├── nvm_remote_version
│ │ │ ├── nvm_remote_versions
│ │ │ ├── nvm_stdout_is_terminal
│ │ │ ├── nvm_strip_iojs_prefix
│ │ │ ├── nvm_strip_path
│ │ │ ├── nvm_supports_xz
│ │ │ ├── nvm_tree_contains_path
│ │ │ ├── nvm_use_if_needed
│ │ │ ├── nvm_validate_implicit_alias
│ │ │ ├── nvm_version
│ │ │ ├── nvm_version_dir
│ │ │ ├── nvm_version_greater
│ │ │ ├── nvm_version_path
│ │ │ ├── nvm_wrap_with_color_code
│ │ │ ├── nvm_write_nvmrc
│ │ │ └── security_wget_injection
│ │ ├── nvm should remove the last trailing slash in $NVM_DIR
│ │ ├── setup
│ │ ├── setup_dir
│ │ ├── teardown
│ │ └── teardown_dir
│ ├── install_script/
│ │ ├── install_nvm_from_git
│ │ ├── nvm_check_global_modules
│ │ ├── nvm_detect_profile
│ │ ├── nvm_do_install
│ │ ├── nvm_download
│ │ ├── nvm_install_dir
│ │ ├── nvm_install_profile_skip
│ │ ├── nvm_install_with_aliased_dot
│ │ ├── nvm_install_with_node_version
│ │ ├── nvm_profile_is_bash_or_zsh
│ │ ├── nvm_reset
│ │ └── nvm_source
│ ├── installation_iojs/
│ │ ├── install already installed uses it
│ │ ├── install from binary
│ │ ├── install from source
│ │ ├── install two versions and use the latest one
│ │ ├── install version specified in .nvmrc from binary
│ │ ├── install version specified in .nvmrc from source
│ │ ├── install while reinstalling packages
│ │ ├── nvm install v1 works
│ │ ├── setup_dir
│ │ └── teardown_dir
│ ├── installation_node/
│ │ ├── default-packages
│ │ ├── install LTS
│ │ ├── install already installed uses it
│ │ ├── install from binary
│ │ ├── install from binary with binary flag set
│ │ ├── install from source
│ │ ├── install from source with thread parameter
│ │ ├── install from source without V8 snapshot for ARM
│ │ ├── install hook
│ │ ├── install latest npm
│ │ ├── install on bash with ERR trap and set -E
│ │ ├── install two versions and use the latest one
│ │ ├── install version specified in .nvmrc from binary
│ │ ├── install while reinstalling packages
│ │ ├── install with --alias
│ │ ├── install with --default
│ │ ├── install with --latest-npm
│ │ ├── setup_dir
│ │ └── teardown_dir
│ ├── mocks/
│ │ ├── isainfo_amd64
│ │ ├── isainfo_x86
│ │ ├── pkg_info_amd64
│ │ ├── pkg_info_fail
│ │ ├── pkg_info_x86
│ │ ├── uname_linux_armv8l
│ │ ├── uname_osx_amd64
│ │ ├── uname_osx_x86
│ │ ├── uname_smartos_amd64
│ │ └── uname_smartos_x86
│ ├── slow/
│ │ ├── Running 'nvm current' should display current nvm environment
│ │ ├── nvm exec/
│ │ │ ├── Running 'nvm exec --lts' should work
│ │ │ ├── Running 'nvm exec --silent' should work
│ │ │ ├── Running 'nvm exec 0.x' should work
│ │ │ ├── Running 'nvm exec' should pick up .nvmrc version
│ │ │ ├── Running 'nvm exec' with help should not parse
│ │ │ ├── setup_dir
│ │ │ └── teardown_dir
│ │ ├── nvm reinstall-packages/
│ │ │ ├── Running 'nvm copy-packages $(nvm ls current)' should error out
│ │ │ ├── setup_dir
│ │ │ ├── should work as expected
│ │ │ ├── teardown_dir
│ │ │ ├── test-npmlink/
│ │ │ │ ├── index.js
│ │ │ │ └── package.json
│ │ │ └── works with no installs
│ │ ├── nvm run/
│ │ │ ├── Running 'nvm run --harmony --version' should work
│ │ │ ├── Running 'nvm run --lts' should work
│ │ │ ├── Running 'nvm run --silent' should work
│ │ │ ├── Running 'nvm run 0.x' should error out sensibly when 0.x is not installed
│ │ │ ├── Running 'nvm run 0.x' should work
│ │ │ ├── Running 'nvm run' should pick up .nvmrc version
│ │ │ ├── setup_dir
│ │ │ └── teardown_dir
│ │ ├── nvm uninstall/
│ │ │ ├── Running 'nvm uninstall 0.12.6' uninstalls v0.12.6
│ │ │ ├── Running 'nvm uninstall' with incorrect file permissions fails nicely
│ │ │ ├── setup_dir
│ │ │ └── teardown_dir
│ │ ├── nvm use/
│ │ │ ├── Running 'nvm use --lts' uses latest LTS version
│ │ │ ├── Running 'nvm use --lts=foo' uses latest 'foo' LTS version
│ │ │ ├── Running 'nvm use iojs' uses latest io.js version
│ │ │ ├── Running 'nvm use lts' shows actionable error
│ │ │ ├── Running 'nvm use node --silent' doesn't print anything
│ │ │ ├── Running 'nvm use node' uses latest stable node version
│ │ │ ├── Running 'nvm use v1.0.0' uses iojs-v1.0.0 iojs version
│ │ │ ├── Running 'nvm use' calls 'nvm_die_on_prefix'
│ │ │ ├── Running 'nvm use' with nvmrc containing not installed version
│ │ │ ├── setup_dir
│ │ │ └── teardown_dir
│ │ └── nvm_get_latest/
│ │ ├── nvm_get_latest
│ │ └── nvm_get_latest failed redirect
│ ├── sourcing/
│ │ ├── Sourcing nvm.sh global alias bug
│ │ ├── Sourcing nvm.sh should keep version if one is active
│ │ ├── Sourcing nvm.sh should use the default if available and no nvm node is loaded
│ │ ├── Sourcing nvm.sh with --install and .nvmrc should install it
│ │ ├── Sourcing nvm.sh with --install should install the default
│ │ ├── Sourcing nvm.sh with --no-use should not use anything
│ │ ├── Sourcing nvm.sh with no default should return 0
│ │ ├── setup_dir
│ │ └── teardown_dir
│ └── xenial/
│ ├── install from source
│ ├── install from source implicitly
│ ├── install from source with thread parameter
│ ├── install from source without V8 snapshot for ARM
│ ├── install hook
│ ├── install version specified in .nvmrc from source
│ └── node 0.6.21 should install 0.6.21-pre
└── update_test_mocks.sh
================================================
FILE CONTENTS
================================================
================================================
FILE: .dockerignore
================================================
HEAD
.cache
v*
alias
# For testing
test/bak
.urchin.log
.urchin_stdout
test/**/test_output
test/**/.nvmrc
node_modules/
npm-debug.log
.DS_Store
current
================================================
FILE: .editorconfig
================================================
root = true
[*]
tab_width = 2
indent_size = 2
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.txt]
indent_size = false
[test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias]
indent_size = false
[test/fast/Listing versions/Running 'nvm ls --no-alias' does not call into nvm_alias]
indent_size = false
[test/fast/Unit tests/mocks/**]
insert_final_newline = off
[test/**/.urchin*]
insert_final_newline = off
[Makefile]
indent_style = tab
[test/fixtures/nvmrc/**]
indent_style = off
insert_final_newline = off
[test/fixtures/actual/alias/empty]
insert_final_newline = off
================================================
FILE: .gitattributes
================================================
* text=auto eol=lf
================================================
FILE: .github/FUNDING.yml
================================================
# These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/nvm
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
================================================
FILE: .github/INCIDENT_RESPONSE_PLAN.md
================================================
# Incident Response Process for **nvm**
## Reporting a Vulnerability
We take the security of **nvm** very seriously. If you believe you’ve found a security vulnerability, please inform us responsibly through coordinated disclosure.
### How to Report
> **Do not** report security vulnerabilities through public GitHub issues, discussions, or social media.
Instead, please use one of these secure channels:
1. **GitHub Security Advisories**
Use the **Report a vulnerability** button in the Security tab of the [nvm-sh/nvm repository](https://github.com/nvm-sh/nvm).
2. **Email**
Follow the posted [Security Policy](https://github.com/nvm-sh/nvm/security/policy).
### What to Include
**Required Information:**
- Brief description of the vulnerability type
- Affected version(s) and components
- Steps to reproduce the issue
- Impact assessment (what an attacker could achieve)
**Helpful Additional Details:**
- Full paths of affected scripts or files
- Specific commit or branch where the issue exists
- Required configuration to reproduce
- Proof-of-concept code (if available)
- Suggested mitigation or fix
## Our Response Process
**Timeline Commitments:**
- **Initial acknowledgment**: Within 24 hours
- **Detailed response**: Within 3 business days
- **Status updates**: Every 7 days until resolved
- **Resolution target**: 90 days for most issues
**What We’ll Do:**
1. Acknowledge your report and assign a tracking ID
2. Assess the vulnerability and determine severity
3. Develop and test a fix
4. Coordinate disclosure timeline with you
5. Release a security update and publish an advisory and CVE
6. Credit you in our security advisory (if desired)
## Disclosure Policy
- **Coordinated disclosure**: We’ll work with you on timing
- **Typical timeline**: 90 days from report to public disclosure
- **Early disclosure**: If actively exploited
- **Delayed disclosure**: For complex issues
## Scope
**In Scope:**
- **nvm** project (all supported versions)
- Installation and update scripts (`install.sh`, `nvm.sh`)
- Official documentation and CI/CD integrations
- Dependencies with direct security implications
**Out of Scope:**
- Third-party forks or mirrors
- Platform-specific installs outside core scripts
- Social engineering or physical attacks
- Theoretical vulnerabilities without practical exploitation
## Security Measures
**Our Commitments:**
- Regular vulnerability scanning via GitHub Actions
- Automated security checks in CI/CD pipelines
- Secure scripting practices and mandatory code review
- Prompt patch releases for critical issues
**User Responsibilities:**
- Keep **nvm** updated
- Verify script downloads via PGP signatures
- Follow secure configuration guidelines for shell environments
## Legal Safe Harbor
**We will NOT:**
- Initiate legal action
- Contact law enforcement
- Suspend or terminate your access
**You must:**
- Only test against your own installations
- Not access, modify, or delete user data
- Not degrade service availability
- Not publicly disclose before coordinated disclosure
- Act in good faith
## Recognition
- **Advisory Credits**: Credit in GitHub Security Advisories (unless anonymous)
## Security Updates
**Stay Informed:**
- Subscribe to GitHub releases for **nvm**
- Enable GitHub Security Advisory notifications
**Update Process:**
- Patch releases (e.g., v0.40.3 → v0.40.4)
- Out-of-band releases for critical issues
- Advisories via GitHub Security Advisories
## Contact Information
- **Security reports**: Security tab of [nvm-sh/nvm](https://github.com/nvm-sh/nvm/security)
- **General inquiries**: GitHub Discussions or Issues
================================================
FILE: .github/ISSUE_TEMPLATE/config.yml
================================================
blank_issues_enabled: false
================================================
FILE: .github/ISSUE_TEMPLATE/issue_template.md
================================================
---
name: File an issue…
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
<!-- Thank you for being interested in nvm! Please help us by filling out the following form if you‘re having trouble. If you have a feature request, or some other question, please feel free to clear out the form. Thanks! -->
#### Operating system and version:
#### `nvm debug` output:
<details>
<!-- do not delete the following blank line -->
```sh
```
</details>
#### `nvm ls` output:
<details>
<!-- do not delete the following blank line -->
```sh
```
</details>
#### How did you install `nvm`?
<!-- (e.g. install script in readme, Homebrew) -->
#### What steps did you perform?
#### What happened?
#### What did you expect to happen?
#### Is there anything in any of your profile files that modifies the `PATH`?
<!-- (e.g. `.bashrc`, `.bash_profile`, `.zshrc`, etc) -->
<!-- Please remove the following section if it does not apply to you -->
#### If you are having installation issues, or getting "N/A", what does `curl -I --compressed -v https://nodejs.org/dist/` print out?
<details>
<!-- do not delete the following blank line -->
```sh
```
</details>
================================================
FILE: .github/SECURITY.md
================================================
# Security
Please file a private vulnerability report via GitHub, email [@ljharb](https://github.com/ljharb), or see https://tidelift.com/security if you have a potential security vulnerability to report.
## Escalation
If you do not receive an acknowledgement of your report within 6 business days, or if you cannot find a private security contact for the project, you may escalate to the OpenJS Foundation CNA at `security@lists.openjsf.org`.
If the project acknowledges your report but does not provide any further response or engagement within 14 days, escalation is also appropriate.
## OpenSSF CII Best Practices
[](https://bestpractices.coreinfrastructure.org/projects/684)
There are three “tiers”: passing, silver, and gold.
### Passing
We meet 100% of the “passing” criteria.
### Silver
We meet 100% of the “silver” criteria.
### Gold
We meet 78% of the “gold” criteria. The gaps are as follows:
- because we only have one maintainer, the project has no way to continue if that maintainer stops being active.
- We do not include a copyright or license statement in each source file. Efforts are underway to change this archaic practice into a suggestion instead of a hard requirement.
## Threat Model
See [THREAT_MODEL.md](.github/THREAT_MODEL.md).
## Incident Response Plan
Please see our [Incident Response Plan](.github/INCIDENT_RESPONSE_PLAN.md).
================================================
FILE: .github/THREAT_MODEL.md
================================================
# `nvm` Threat Model
## Introduction
Threat model analysis assists organizations to proactively identify potential security threats and vulnerabilities, enabling them to develop effective strategies to mitigate these risks before they are exploited by attackers.
Furthermore, this often helps to improve the overall security and resilience of a system or application.
The aim of this section is to facilitate the identification of potential security threats and vulnerabilities that may be exploited by adversaries, along with possible outcomes and appropriate mitigations.
## Relevant assets and threat actors
The following assets are considered important for the `nvm` project:
- `nvm` source code and project documentation
- Underlying `nvm` dependencies
- `nvm` development infrastructure
- `nvm` installed devices including servers
The following threat actors are considered relevant to the `nvm` application:
- External malicious attackers
- Internal malicious attackers
- Services
- Malicious insider actors
- Third-party libraries
## Attack surface for external/internal attackers and services
In threat modeling, an attack surface refers to any possible point of entry that an attacker might use to exploit a system or application.
This includes all the paths and interfaces that an attacker may use to access, manipulate or extract sensitive data from a system.
By understanding the attack surface, organizations are typically able to identify potential attack vectors and implement appropriate countermeasures to mitigate risks.
In the following diagrams, _External Malicious Attacker_ applies to threat actors who do not yet have direct access to the `nvm` application and the underlying operating system, while the _Internal Malicious Attacker_ applies to an attacker with access to the device (computer, server), potentially after successfully exploiting a threat from the _External Malicious Attacker_ scenario.
**Please note that some of the external threats may be also exploitable from internal threats and vice versa.**
<img src="./external-threat-actor.png" alt="Fig.: Possible attacks from internal and external threat actors and services" />
Fig.: Possible attacks from internal and external threat actors and services
## Identified threats
The identified threats against the `nvm` application are as follows:
### Threat ID 1: `nvm` commands
Overview: The `nvm` commands and subcommands take user input for handling and executing appropriate functions from the project directory (or any parent directory).
When user-controlled inputs are not adequately validated and later passed to the `nvm` functions as a part of a command, an attacker might be able to execute operating system commands triggered by any parsing functionality.
Possible Outcome: Attacks against `nvm` commands could lead to unauthorized access to user data or unauthorized access to the device (i.e. laptop or server, depending on where `nvm` is installed), resulting in loss of user private data stored on the device, among other possibilities.
Recommendation: Input validation should be implemented to prevent attackers from requesting operating system commands.
Similarly, secure coding practices ought to be in place to minimize the risk of buffer overflow vulnerabilities.
### Threat ID 2: URI scheme
Overview: `nvm` commands heavily use the [Secure HyperText Transfer](https://datatracker.ietf.org/doc/html/rfc2660) protocol for `nvm` related actions.
Missing [scheme](https://datatracker.ietf.org/doc/html/rfc3986#section-3.1) validation for any `nvm` command might result in file retrieval, enumeration, file overwrite, or [path traversal](https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/05-Authorization_Testing/01-Testing_Directory_Traversal_File_Include) attacks.
An example of this could be path validation for [`nvm_download`](https://github.com/nvm-sh/nvm/blob/ef7fc2f2c06ad75fe7fbabf28d427561ae7b007d/nvm.sh#L118), among many other possibilities.
Possible Outcome: Security misconfiguration flaws for URI scheme may lead to unauthorized access to user data, as well as data integrity compromises.
Recommendation: Adequate input validation should be implemented to prevent attackers from enumerating, retrieving and writing to application files and paths.
### Threat ID 3: Communication channel
Overview: The `nvm` commands and its subcommands use network protocol to communicate with external services.
Insecure communication may allow malicious attackers to perform [_Man-in-the-Middle_](https://owasp.org/www-community/attacks/Manipulator-in-the-middle_attack) attacks in order to manipulate the data sent during the users’ active connection.
Possible Outcome: Usage of plaintext communication protocols, like HTTP could lead to data sniffing and modification through insecure communications channels.
Recommendation: Mitigation countermeasures such as data encryption should be in place to prevent data manipulation via insecure communication channels.
### Threat ID 4: Environment variables
Overview: Each `nvm` installation defines its environment variables, which should be secured from internal malicious attackers, preventing access control attack vectors.
Missing stringent restrictions on setting variables, might allow attackers to prepare various targeted attacks against other local users, who use `nvm` in their user space.
For example, [_Privilege Escalation_](https://owasp.org/Top10/A01_2021-Broken_Access_Control/), [_Command Injection_](https://cwe.mitre.org/data/definitions/77.html), as well as many other parser-related attacks.
Possible Outcome: Attacks against environment variables could lead to unauthorized access to the user space, resulting in the loss of user private data and disruptions in service availability.
Recommendation: Adequate hardening of configuration file permissions should be in place for all relevant configuration files, as this provides protection against attackers able to manipulate variables and inject malicious code.
## Attack surface for malicious insider actors and third-party libraries
The following diagram summarizes the main possible threats against the `nvm` project from malicious insider actors and third-party libraries:
<img src="./insider-threat-actor-and-libs.png" alt="Fig.: Possible attacks from insider threat actors and third-party libraries" />
Fig.: Possible attacks from insider threat actors and third-party libraries
The identified threats against the `nvm` project are as follows:
### Threat ID 1: Insider threat actor
**Overview**: An insider threat actor, such as an `nvm` project contributor or employee with access to the code base, might abuse their role in the organization to modify the `nvm` application source code.
For example, intentionally adding malicious code snippets, clearing logs after being written and/or modifying specific sections of the documentation.
**Possible Outcome**: Reputation damage, financial losses.
**Recommendation**: Secure coding practices, code reviews, automated code scanning and separation of duties (i.e. requiring at least two developers to approve any code change) are potentially useful security controls to identify and mitigate vulnerabilities that may be introduced by an insider threat actor.
### Threat ID 2: Third-party libraries
**Overview**: Please note that while `nvm` does not currently make use of any third-party libraries, this might become an attack vector if that changes in the future.
Third-party libraries may introduce potential risks related to maintaining security requirements by third-party vendors.
As a result, third-party libraries used by the `nvm` project, might contain vulnerabilities, such as [_Buffer Overflows_](https://owasp.org/www-community/vulnerabilities/Buffer_Overflow), [_Format String Vulnerabilities_](https://owasp.org/www-community/attacks/Format_string_attack), as well as many other types of weaknesses that, in a worst-case scenario may lead to _Remote Code Execution_ (_RCE_).
Additionally, the maintainer of a third-party dependency might introduce a vulnerability on purpose, or be compromised by an attacker that subsequently introduces vulnerable code.
**Possible Outcome**: Code vulnerabilities may lead to unauthorized access to user data, loss of user private data, service disruptions and reputation damage.
**Recommendation**: Third-party libraries should be kept up-to-date, applying patches to address publicly known vulnerabilities in a timely fashion.
Monitoring and logging capabilities should also be in place to detect and respond to potential attacks.
SLSA compliance may also be considered for further supply chain security hardening.
================================================
FILE: .github/workflows/codeql-analysis.yml
================================================
name: "Code scanning - action"
on:
push:
pull_request:
schedule:
- cron: '0 17 * * 4'
permissions:
contents: read
jobs:
CodeQL-Build:
# CodeQL runs on ubuntu-latest and windows-latest
permissions:
actions: read # for github/codeql-action/init to get workflow details
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/autobuild to send a status report
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: false
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v4
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
================================================
FILE: .github/workflows/latest-npm.yml
================================================
name: 'Tests: `nvm install-latest-npm`'
on: [pull_request, push]
permissions:
contents: read
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
latest: ${{ steps.set-matrix.outputs.requireds }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
iojs.org:443
nodejs.org:443
raw.githubusercontent.com:443
- uses: ljharb/actions/node/matrix@main
id: set-matrix
with:
versionsAsRoot: true
type: majors
preset: '>=1'
nodes:
needs: [matrix]
permissions:
contents: read
name: 'nvm install-latest-npm'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
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.1"
- node-version: "9.0"
- node-version: "6.1"
- node-version: "5.9"
- node-version: "4.6"
- node-version: "4.5"
- node-version: "4.4"
- node-version: "0.12"
- node-version: "0.10"
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
raw.githubusercontent.com:443
iojs.org:443
nodejs.org:443
registry.npmjs.org:443
- uses: actions/checkout@v6
- uses: ljharb/actions/node/install@main
name: 'install node'
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
skip-install: true
skip-latest-npm: true
- run: npm --version
- run: '. ./nvm.sh ; nvm install-latest-npm'
name: 'nvm install-latest-npm'
- run: npm --version
node:
permissions:
contents: none
name: 'nvm install-latest-npm'
needs: [nodes]
runs-on: ubuntu-latest
steps:
- run: true
================================================
FILE: .github/workflows/lint.yml
================================================
name: 'Tests: linting'
on: [pull_request, push]
permissions:
contents: read
jobs:
eclint:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
raw.githubusercontent.com:443
nodejs.org:443
registry.npmjs.org:443
- uses: actions/checkout@v6
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: 'lts/*'
- run: npm run eclint
dockerfile_lint:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@v2
with:
allowed-endpoints:
ghcr.io:443
github.com:443
raw.githubusercontent.com:443
pkg-containers.githubusercontent.com:443
nodejs.org:443
registry.npmjs.org:443
- uses: actions/checkout@v6
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: 'lts/*'
- run: npm run dockerfile_lint
doctoc:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
raw.githubusercontent.com:443
nodejs.org:443
registry.npmjs.org:443
- uses: actions/checkout@v6
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: 'lts/*'
- run: npm run doctoc:check
test_naming:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
raw.githubusercontent.com:443
- uses: actions/checkout@v6
- name: check tests filenames
run: ./rename_test.sh --check
all:
permissions:
contents: none
name: 'all linting'
needs: [eclint, dockerfile_lint, doctoc, test_naming]
runs-on: ubuntu-latest
steps:
- run: true
================================================
FILE: .github/workflows/nodejs-org.yml
================================================
name: 'Update nodejs.org'
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'nvm version tag (e.g., v0.40.4). Defaults to latest release.'
required: false
default: ''
permissions:
contents: read
jobs:
update-nodejs-org:
if: github.repository == 'nvm-sh/nvm' && github.actor == 'ljharb'
permissions:
contents: none
name: 'Create PR to nodejs/nodejs.org'
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
api.github.com:443
- name: Extract and validate version
id: version
run: |
set -euo pipefail
INPUT_VERSION="${{ inputs.version }}"
if [ -n "${INPUT_VERSION}" ]; then
TAG="${INPUT_VERSION}"
elif [ "${GITHUB_REF_TYPE}" = "tag" ]; then
TAG="${GITHUB_REF#refs/tags/}"
else
TAG="$(gh api "repos/${GITHUB_REPOSITORY}/releases/latest" --jq '.tag_name')"
fi
if ! printf '%s\n' "${TAG}" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::notice::Tag '${TAG}' does not match expected format vX.Y.Z, skipping"
exit 0
fi
printf 'tag=%s\n' "${TAG}" >> "${GITHUB_OUTPUT}"
env:
GH_TOKEN: ${{ github.token }}
- name: Set up fork and branch
if: steps.version.outputs.tag
id: fork
run: |
set -euo pipefail
BRANCH="nvm-${{ steps.version.outputs.tag }}"
gh repo fork nodejs/nodejs.org --clone=false 2>&1 || true
FORK_OWNER="$(gh api user --jq '.login')"
DEFAULT_BRANCH="$(gh api repos/nodejs/nodejs.org --jq '.default_branch')"
UPSTREAM_SHA="$(gh api "repos/nodejs/nodejs.org/git/ref/heads/${DEFAULT_BRANCH}" --jq '.object.sha')"
# Create or reset branch on fork to upstream HEAD
if ! gh api "repos/${FORK_OWNER}/nodejs.org/git/refs" \
-f "ref=refs/heads/${BRANCH}" \
-f "sha=${UPSTREAM_SHA}" > /dev/null 2>&1; then
gh api "repos/${FORK_OWNER}/nodejs.org/git/refs/heads/${BRANCH}" \
-X PATCH \
-f "sha=${UPSTREAM_SHA}" \
-f "force=true" > /dev/null
fi
printf 'fork_owner=%s\n' "${FORK_OWNER}" >> "${GITHUB_OUTPUT}"
printf 'branch=%s\n' "${BRANCH}" >> "${GITHUB_OUTPUT}"
env:
GH_TOKEN: ${{ secrets.NODEJS_ORG_TOKEN }}
- name: Update nvm version in English snippet
if: steps.version.outputs.tag
id: update
run: |
set -euo pipefail
NEW_VERSION="${{ steps.version.outputs.tag }}"
FORK_OWNER="${{ steps.fork.outputs.fork_owner }}"
BRANCH="${{ steps.fork.outputs.branch }}"
FILE_PATH="apps/site/snippets/en/download/nvm.bash"
PATTERN='nvm-sh/nvm/v[0-9]+\.[0-9]+\.[0-9]+/install\.sh'
REPLACEMENT="nvm-sh/nvm/${NEW_VERSION}/install.sh"
# Get file content via API
FILE_RESPONSE="$(gh api "repos/${FORK_OWNER}/nodejs.org/contents/${FILE_PATH}?ref=${BRANCH}")"
FILE_SHA="$(printf '%s' "${FILE_RESPONSE}" | jq -r '.sha')"
printf '%s' "${FILE_RESPONSE}" | jq -r '.content' | base64 -d > "${RUNNER_TEMP}/nvm.bash"
# Validate exactly 1 match
MATCH_COUNT="$(grep -cE "${PATTERN}" "${RUNNER_TEMP}/nvm.bash" || true)"
if [ "${MATCH_COUNT}" -eq 0 ]; then
echo "::error::No nvm version pattern found in ${FILE_PATH}"
exit 1
fi
if [ "${MATCH_COUNT}" -ne 1 ]; then
echo "::error::Expected exactly 1 nvm version match in ${FILE_PATH}, found ${MATCH_COUNT}"
exit 1
fi
# Replace and check for changes
cp "${RUNNER_TEMP}/nvm.bash" "${RUNNER_TEMP}/nvm.bash.orig"
sed -i -E "s|${PATTERN}|${REPLACEMENT}|g" "${RUNNER_TEMP}/nvm.bash"
if cmp -s "${RUNNER_TEMP}/nvm.bash" "${RUNNER_TEMP}/nvm.bash.orig"; then
echo "::notice::English snippet already has version ${NEW_VERSION}"
exit 0
fi
if ! grep -qF "${REPLACEMENT}" "${RUNNER_TEMP}/nvm.bash"; then
echo "::error::Replacement verification failed in ${FILE_PATH}"
exit 1
fi
# Update file via GitHub API (avoids git push workflow scope requirement)
NEW_CONTENT_B64="$(base64 -w 0 < "${RUNNER_TEMP}/nvm.bash")"
gh api "repos/${FORK_OWNER}/nodejs.org/contents/${FILE_PATH}" \
-X PUT \
-f "message=meta: bump nvm to ${NEW_VERSION}" \
-f "content=${NEW_CONTENT_B64}" \
-f "sha=${FILE_SHA}" \
-f "branch=${BRANCH}" \
-f "committer[name]=github-actions[bot]" \
-f "committer[email]=41898282+github-actions[bot]@users.noreply.github.com" > /dev/null
printf 'updated=true\n' >> "${GITHUB_OUTPUT}"
env:
GH_TOKEN: ${{ secrets.NODEJS_ORG_TOKEN }}
- name: Create pull request
if: steps.update.outputs.updated
run: |
set -euo pipefail
NEW_VERSION="${{ steps.version.outputs.tag }}"
FORK_OWNER="${{ steps.fork.outputs.fork_owner }}"
BRANCH="${{ steps.fork.outputs.branch }}"
BODY="Updates the English nvm install snippet to [\`${NEW_VERSION}\`](https://github.com/nvm-sh/nvm/releases/tag/${NEW_VERSION}). The translation system handles other locales.
Ref: https://github.com/nodejs/nodejs.org/issues/8628"
gh pr create \
--repo nodejs/nodejs.org \
--head "${FORK_OWNER}:${BRANCH}" \
--title "meta: bump nvm to ${NEW_VERSION}" \
--body "${BODY}"
env:
GH_TOKEN: ${{ secrets.NODEJS_ORG_TOKEN }}
================================================
FILE: .github/workflows/nvm-install-test.yml
================================================
name: 'Tests: nvm install with set -e'
on:
pull_request:
push:
workflow_dispatch:
inputs:
ref:
description: 'git ref to use'
required: false
default: 'HEAD'
permissions:
contents: read
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- id: matrix
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.ref }}" ]; then
echo "matrix=\"[\"${{ github.event.inputs.ref }}\"]\"" >> $GITHUB_OUTPUT
else
TAGS="$((echo "HEAD" && git tag --sort=-v:refname --merged HEAD --format='%(refname:strip=2) %(creatordate:short)' | grep '^v' | while read tag date; do
if [ "$(uname)" == "Darwin" ]; then
timestamp=$(date -j -f "%Y-%m-%d" "$date" +%s)
threshold=$(date -j -v-4y +%s)
else
timestamp=$(date -d "$date" +%s)
threshold=$(date -d "4 years ago" +%s)
fi
if [ $timestamp -ge $threshold ]; then echo "$tag"; fi
done) | xargs)"
echo $TAGS
TAGS_JSON=$(printf "%s\n" $TAGS | jq -R . | jq -sc .)
echo "matrix=${TAGS_JSON}" >> $GITHUB_OUTPUT
fi
test:
needs: [matrix]
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.ref == 'v0.40.0' }} # https://github.com/nvm-sh/nvm/issues/3405
strategy:
fail-fast: false
matrix:
ref: ${{ fromJson(needs.matrix.outputs.matrix) }}
has-nvmrc:
- 'no nvmrc'
- 'nvmrc'
shell-level:
- 1 shlvl
- 2 shlvls
steps:
- uses: actions/checkout@v6
- name: resolve HEAD to sha
run: |
if [ '${{ matrix.ref }}' = 'HEAD' ]; then
REF="$(git rev-parse HEAD)"
else
REF="${{ matrix.ref }}"
fi
echo "resolved ref: ${REF}"
echo "ref="$REF"" >> $GITHUB_ENV
- run: echo $- # which options are set
- run: echo node > .nvmrc
if: ${{ matrix.has-nvmrc == 'nvmrc' }}
- run: curl -I --compressed -v https://nodejs.org/dist/
- name: 'install nvm'
run: |
set -e
export NVM_INSTALL_VERSION="${ref}"
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/${ref}/install.sh" | bash
- name: nvm --version
run: |
set +e
. $NVM_DIR/nvm.sh && nvm --version
- name: nvm install in 1 shell level, ${{ matrix.has-nvmrc }}
if: ${{ matrix.shell-level == '1 shlvl' }}
run: |
set -ex
. $NVM_DIR/nvm.sh
echo nvm.sh sourced
nvm --version
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
nvm install
fi
- name: nvm install in 2 shell levels, ${{ matrix.has-nvmrc }}
if: ${{ matrix.shell-level == '2 shlvls' }}
run: |
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version && nvm install"
else
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version"
fi
finisher:
runs-on: ubuntu-latest
needs: [test]
steps:
- run: true
================================================
FILE: .github/workflows/rebase.yml
================================================
name: Automatic Rebase
on: [pull_request_target]
permissions: read-all
jobs:
_:
name: "Automatic Rebase"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ljharb/rebase@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
================================================
FILE: .github/workflows/release.yml
================================================
name: 'Tests: release process'
on: [pull_request, push]
permissions:
contents: read
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
api.github.com:443
objects.githubusercontent.com:443
raw.githubusercontent.com:443
release-assets.githubusercontent.com:443
registry.npmjs.org:443
- uses: actions/checkout@v6
with:
fetch-tags: true
- uses: actions/setup-node@v6
with:
node-version: "14"
- run: npm install
- name: Configure git
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git fetch --unshallow --tags -f || git fetch --tags -f
- name: Attempt `make release` process
run: echo proceed | make TAG=99.99.99 release
env:
GIT_EDITOR: "sed -i '1 s/^/99.99.99 make release test/'"
- name: Ensure tag is created
run: git tag | grep v99.99.99
================================================
FILE: .github/workflows/require-allow-edits.yml
================================================
name: Require “Allow Edits”
on: [pull_request_target]
permissions: read-all
jobs:
_:
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- uses: ljharb/require-allow-edits@main
================================================
FILE: .github/workflows/shellcheck.yml
================================================
name: 'Tests: shellcheck'
on: [pull_request, push]
permissions:
contents: read
jobs:
shellcheck_matrix:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shell:
- bash
- sh
- dash
- ksh
file:
- nvm.sh
include:
- shell: bash
file: install.sh # only supported on bash
- shell: bash
file: bash_completion # only needed in bash/zsh
- shell: bash
file: nvm-exec # only runs in bash
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
ghcr.io:443
github.com:443
pkg-containers.githubusercontent.com:443
formulae.brew.sh:443
- uses: actions/checkout@v6
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Install latest shellcheck
run: brew install shellcheck
env:
HOMEBREW_NO_ANALYTICS: 1
- run: which shellcheck
- run: shellcheck --version
- name: Run shellcheck on ${{ matrix.file }}
run: shellcheck -s ${{ matrix.shell }} ${{ matrix.file }}
shellcheck:
permissions:
contents: none
needs: [shellcheck_matrix]
runs-on: ubuntu-latest
steps:
- run: true
================================================
FILE: .github/workflows/tests-fast.yml
================================================
name: 'Tests: fast'
on: [push, pull_request]
permissions:
contents: read
jobs:
fast:
permissions:
contents: read
name: 'fast (${{ matrix.shell }}, ${{ matrix.awk }})'
runs-on: ubuntu-latest
defaults:
run:
shell: 'script -q -e -c "${{ matrix.shell }} {0}"'
strategy:
fail-fast: false
matrix:
shell:
- sh
- bash
- dash
- zsh
# - ksh
awk:
- gawk
- mawk
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
registry.npmjs.org:443
raw.githubusercontent.com:443
nodejs.org:443
iojs.org:443
unofficial-builds.nodejs.org:443
azure.archive.ubuntu.com:80
packages.microsoft.com:443
registry-1.docker.io:443
auth.docker.io:443
production.cloudflare.docker.com:443
- uses: actions/checkout@v6
with:
submodules: true
- name: Install zsh, additional shells, and awk variant
run: |
sudo apt-get update
sudo apt-get install -y zsh ${{ matrix.awk }}
if [ "${{ matrix.shell }}" != "sh" ] && [ "${{ matrix.shell }}" != "bash" ] && [ "${{ matrix.shell }}" != "zsh" ]; then
sudo apt-get install -y ${{ matrix.shell }}
fi
# Set the selected awk as the default
sudo update-alternatives --set awk /usr/bin/${{ matrix.awk }}
shell: bash
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
- run: awk --version 2>&1 | head -1 || awk -W version 2>&1 | head -1
- run: curl --version
- run: wget --version
- uses: ljharb/actions/node/install@main
name: 'npm install && version checks'
with:
node-version: 'lts/*'
skip-ls-check: true
- run: npm ls urchin
- run: npx which urchin
- run: env
- name: Hide system node
run: |
if [ -f /usr/local/bin/node ]; then sudo mv /usr/local/bin/node /usr/local/bin/node.bak; fi
if [ -f /usr/local/bin/npm ]; then sudo mv /usr/local/bin/npm /usr/local/bin/npm.bak; fi
if [ -f /usr/local/bin/npx ]; then sudo mv /usr/local/bin/npx /usr/local/bin/npx.bak; fi
shell: bash
- name: Run fast tests
run: |
URCHIN_PATH="$(npx which urchin)"
unset NVM_CD_FLAGS NVM_BIN NVM_INC
export NVM_DIR="${{ github.workspace }}"
export PATH="$(echo "$PATH" | tr ':' '\n' | grep -v '\.nvm' | grep -v 'toolcache' | tr '\n' ':')"
make TERM=xterm-256color TEST_SUITE="fast" SHELL="${{ matrix.shell }}" URCHIN="$URCHIN_PATH" test-${{ matrix.shell }}
- name: Restore system node
if: always()
run: |
if [ -f /usr/local/bin/node.bak ]; then sudo mv /usr/local/bin/node.bak /usr/local/bin/node; fi
if [ -f /usr/local/bin/npm.bak ]; then sudo mv /usr/local/bin/npm.bak /usr/local/bin/npm; fi
if [ -f /usr/local/bin/npx.bak ]; then sudo mv /usr/local/bin/npx.bak /usr/local/bin/npx; fi
shell: bash
all:
permissions:
contents: none
name: 'all fast tests'
needs: [fast]
runs-on: ubuntu-latest
steps:
- run: true
================================================
FILE: .github/workflows/tests-installation-iojs.yml
================================================
name: 'Tests: installation_iojs'
on: [push, pull_request]
permissions:
contents: read
jobs:
installation_iojs_without_curl:
permissions:
contents: read
name: 'installation_iojs without curl (${{ matrix.shell }})'
runs-on: ubuntu-latest
defaults:
run:
shell: 'script -q -e -c "${{ matrix.shell }} {0}"'
strategy:
fail-fast: false
matrix:
shell:
- sh
- bash
- dash
- zsh
# - ksh
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
registry.npmjs.org:443
raw.githubusercontent.com:443
nodejs.org:443
iojs.org:443
azure.archive.ubuntu.com:80
packages.microsoft.com:443
- uses: actions/checkout@v6
with:
submodules: true
- name: Install zsh and additional shells
run: |
sudo apt-get update
sudo apt-get install -y zsh
if [ "${{ matrix.shell }}" != "sh" ] && [ "${{ matrix.shell }}" != "bash" ] && [ "${{ matrix.shell }}" != "zsh" ]; then
sudo apt-get install -y ${{ matrix.shell }}
fi
shell: bash
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
- run: wget --version
- uses: ljharb/actions/node/install@main
name: 'npm install && version checks'
with:
node-version: 'lts/*'
skip-ls-check: true
- run: npm ls urchin
- run: npx which urchin
- name: Remove curl
run: sudo apt-get remove curl -y
shell: bash
- run: '! command -v curl'
shell: bash
- run: env
- name: Hide system node
run: |
if [ -f /usr/local/bin/node ]; then sudo mv /usr/local/bin/node /usr/local/bin/node.bak; fi
if [ -f /usr/local/bin/npm ]; then sudo mv /usr/local/bin/npm /usr/local/bin/npm.bak; fi
if [ -f /usr/local/bin/npx ]; then sudo mv /usr/local/bin/npx /usr/local/bin/npx.bak; fi
shell: bash
- name: Run installation_iojs tests
run: |
URCHIN_PATH="$(npx which urchin)"
unset NVM_CD_FLAGS NVM_BIN NVM_INC
export NVM_DIR="${{ github.workspace }}"
export PATH="$(echo "$PATH" | tr ':' '\n' | grep -v '\.nvm' | grep -v 'toolcache' | tr '\n' ':')"
make TERM=xterm-256color TEST_SUITE="installation_iojs" SHELL="${{ matrix.shell }}" URCHIN="$URCHIN_PATH" test-${{ matrix.shell }}
- name: Restore system node
if: always()
run: |
if [ -f /usr/local/bin/node.bak ]; then sudo mv /usr/local/bin/node.bak /usr/local/bin/node; fi
if [ -f /usr/local/bin/npm.bak ]; then sudo mv /usr/local/bin/npm.bak /usr/local/bin/npm; fi
if [ -f /usr/local/bin/npx.bak ]; then sudo mv /usr/local/bin/npx.bak /usr/local/bin/npx; fi
shell: bash
- name: Restore curl
if: always()
run: sudo apt-get install curl -y
shell: bash
all:
permissions:
contents: none
name: 'all installation_iojs tests'
needs: [installation_iojs_without_curl]
runs-on: ubuntu-latest
steps:
- run: true
================================================
FILE: .github/workflows/tests-installation-node.yml
================================================
name: 'Tests: installation_node'
on: [push, pull_request]
permissions:
contents: read
jobs:
installation_node:
permissions:
contents: read
name: "installation_node (${{ matrix.shell }}${{ matrix.without_curl && ', without curl' || '' }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shell:
- sh
- bash
- dash
- zsh
# - ksh
without_curl:
- false
- true
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
registry.npmjs.org:443
raw.githubusercontent.com:443
nodejs.org:443
iojs.org:443
azure.archive.ubuntu.com:80
packages.microsoft.com:443
archive.ubuntu.com:80
security.ubuntu.com:80
production.cloudflare.docker.com:443
registry-1.docker.io:443
auth.docker.io:443
- uses: actions/checkout@v6
with:
submodules: true
- uses: ljharb/actions/node/install@main
name: 'npm install && version checks'
with:
node-version: 'lts/*'
skip-ls-check: true
- run: npm ls urchin
- run: npx which urchin
- name: Run installation_node tests in container
run: |
docker run --rm \
-v "${{ github.workspace }}:/workspace" \
-w /workspace \
-e "TEST_SHELL=${{ matrix.shell }}" \
-e "TERM=xterm-256color" \
-e "DEBIAN_FRONTEND=noninteractive" \
-e "GITHUB_ACTIONS=true" \
-e "WITHOUT_CURL=${{ matrix.without_curl }}" \
ubuntu:16.04 \
bash -c '
set -ex
# Retry apt-get update up to 5 times due to flaky Ubuntu mirrors
# apt-get update can return 0 even with partial failures, so check for warnings
for i in 1 2 3 4 5; do
if apt-get update 2>&1 | tee /tmp/apt-update.log | grep -qE "^(W:|E:|Err:)"; then
echo "apt-get update had warnings/errors, attempt $i/5"
cat /tmp/apt-update.log
sleep $((i * 5))
else
break
fi
done
apt-get install -y git curl wget make build-essential python zsh libssl-dev
if [ "$TEST_SHELL" != "sh" ] && [ "$TEST_SHELL" != "bash" ]; then
apt-get install -y $TEST_SHELL || true
fi
# Use nvm to install Node.js for running urchin
# Node 16 is the last version supporting GLIBC 2.23 (Ubuntu 16.04)
export NVM_DIR="/workspace"
. /workspace/nvm.sh
nvm install 16
nvm use 16
npm ls urchin
URCHIN_PATH="$(npx which urchin)"
# Remove curl if testing without it
if [ "$WITHOUT_CURL" = "true" ]; then
apt-get remove curl -y
! command -v curl
fi
# Now clean up nvm state for the actual tests, but keep NVM_DIR set
nvm deactivate || true
nvm unalias default || true
unset NVM_CD_FLAGS NVM_BIN NVM_INC
export PATH="$(echo "$PATH" | tr ":" "\n" | grep -v "\.nvm" | grep -v "toolcache" | tr "\n" ":")"
# Clean any cached files from the nvm install above
rm -rf "$NVM_DIR/.cache" "$NVM_DIR/versions" "$NVM_DIR/alias"
make TEST_SUITE="installation_node" SHELL="$TEST_SHELL" URCHIN="$URCHIN_PATH" test-$TEST_SHELL
'
all:
permissions:
contents: none
name: 'all installation_node tests'
needs: [installation_node]
runs-on: ubuntu-latest
steps:
- run: true
================================================
FILE: .github/workflows/tests-xenial.yml
================================================
name: 'Tests: xenial'
on: [push, pull_request]
permissions:
contents: read
jobs:
xenial:
permissions:
contents: read
name: 'xenial (${{ matrix.shell }})'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shell:
- sh
- bash
- dash
- zsh
# - ksh
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
registry.npmjs.org:443
raw.githubusercontent.com:443
nodejs.org:443
iojs.org:443
azure.archive.ubuntu.com:80
packages.microsoft.com:443
archive.ubuntu.com:80
security.ubuntu.com:80
production.cloudflare.docker.com:443
registry-1.docker.io:443
auth.docker.io:443
- uses: actions/checkout@v6
with:
submodules: true
- uses: ljharb/actions/node/install@main
name: 'npm install && version checks'
with:
node-version: 'lts/*'
skip-ls-check: true
- run: npm ls urchin
- run: npx which urchin
- name: Run xenial tests in container
run: |
docker run --rm \
-v "${{ github.workspace }}:/workspace" \
-w /workspace \
-e "TEST_SHELL=${{ matrix.shell }}" \
-e "TERM=xterm-256color" \
-e "DEBIAN_FRONTEND=noninteractive" \
-e "GITHUB_ACTIONS=true" \
ubuntu:16.04 \
bash -c '
set -ex
# Retry apt-get update up to 5 times due to flaky Ubuntu mirrors
# apt-get update can return 0 even with partial failures, so check for warnings
for i in 1 2 3 4 5; do
if apt-get update 2>&1 | tee /tmp/apt-update.log | grep -qE "^(W:|E:|Err:)"; then
echo "apt-get update had warnings/errors, attempt $i/5"
cat /tmp/apt-update.log
sleep $((i * 5))
else
break
fi
done
apt-get install -y git curl wget make build-essential python zsh libssl-dev
if [ "$TEST_SHELL" != "sh" ] && [ "$TEST_SHELL" != "bash" ]; then
apt-get install -y $TEST_SHELL || true
fi
# Use nvm to install Node.js for running urchin
# Node 16 is the last version supporting GLIBC 2.23 (Ubuntu 16.04)
export NVM_DIR="/workspace"
. /workspace/nvm.sh
nvm install 16
nvm use 16
npm ls urchin
URCHIN_PATH="$(npx which urchin)"
# Now clean up nvm state for the actual tests, but keep NVM_DIR set
nvm deactivate || true
nvm unalias default || true
unset NVM_CD_FLAGS NVM_BIN NVM_INC
export PATH="$(echo "$PATH" | tr ":" "\n" | grep -v "\.nvm" | grep -v "toolcache" | tr "\n" ":")"
# Clean any cached files from the nvm install above
rm -rf "$NVM_DIR/.cache" "$NVM_DIR/versions" "$NVM_DIR/alias"
make TEST_SUITE="xenial" SHELL="$TEST_SHELL" URCHIN="$URCHIN_PATH" test-$TEST_SHELL
'
all:
permissions:
contents: none
name: 'all xenial tests'
needs: [xenial]
runs-on: ubuntu-latest
steps:
- run: true
================================================
FILE: .github/workflows/tests.yml
================================================
name: urchin tests
on: [push, pull_request]
permissions:
contents: read
jobs:
tests:
permissions:
contents: write
name: "tests"
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
shell: 'script -q -e -c "${{ matrix.shell }} {0}"'
strategy:
fail-fast: false
matrix:
exclude:
- shell: sh
suite: install_script
- shell: dash
suite: install_script
- shell: zsh
suite: install_script
- shell: ksh
suite: install_script
suite:
- install_script
- sourcing
- slow
- installation_iojs
shell:
- sh
- bash
- dash
- zsh
# - ksh
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
registry.npmjs.org:443
raw.githubusercontent.com:443
nodejs.org:443
iojs.org:443
azure.archive.ubuntu.com:80
packages.microsoft.com:443
- uses: actions/checkout@v6
- run: sudo apt-get update; sudo apt-get install ${{ matrix.shell }}
if: matrix.shell == 'zsh' || matrix.shell == 'ksh'
# zsh (https://github.com/actions/runner-images/issues/264) and ksh are not in the ubuntu image
shell: bash
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
- run: curl --version
- run: wget --version
- uses: ljharb/actions/node/install@main
name: 'npm install && version checks'
with:
node-version: 'lts/*'
skip-ls-check: true
- run: npm ls urchin
- run: npx which urchin
- run: env
- name: Run tests
shell: bash
run: |
for attempt in 1 2 3; do
timeout 600 make TERM=xterm-256color TEST_SUITE="${{ matrix.suite }}" SHELL="${{ matrix.shell }}" URCHIN="$(npx which urchin)" test-${{ matrix.shell }} && exit 0
EXIT_CODE=$?
if [ $EXIT_CODE -ne 124 ]; then
exit $EXIT_CODE
fi
echo "Attempt ${attempt} timed out; retrying..."
done
echo "All 3 attempts timed out."
exit 1
nvm:
permissions:
contents: none
name: 'all test suites, all shells'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: true
================================================
FILE: .github/workflows/toc.yml
================================================
name: update readme TOC
on: [push]
permissions:
contents: read
jobs:
_:
permissions:
contents: write
name: "update readme TOC"
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
registry.npmjs.org:443
api.github.com:443
- uses: actions/checkout@v6
with:
# https://github.com/actions/checkout/issues/217#issue-599945005
# pulls all commits (needed for lerna / semantic release to correctly version)
fetch-depth: "0"
# pulls all tags (needed for lerna / semantic release to correctly version)
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- uses: actions/setup-node@v6
with:
node-version: 'lts/*'
- run: npm install
- run: npm run doctoc
- name: commit changes
uses: ljharb/actions-js-build/commit@v3+amendpush
with:
amend: true
force: true
================================================
FILE: .github/workflows/windows-npm.yml
================================================
name: 'Tests on Windows: `nvm install`'
on: [pull_request, push]
permissions:
contents: read
env:
NVM_INSTALL_GITHUB_REPO: ${{ github.repository }}
NVM_INSTALL_VERSION: ${{ github.sha }}
jobs:
msys_fail_install:
# Default installation does not work due to npm_config_prefix set to C:\npm\prefix
permissions:
contents: none
name: 'MSYS fail prefix nvm install'
runs-on: windows-latest
steps:
- name: Retrieve nvm
shell: bash
run: |
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash
. "$HOME/.nvm/nvm.sh"
! nvm install --lts
msys_matrix:
permissions:
contents: none
name: 'MSYS nvm install'
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
npm-node-version:
- '--lts'
- '--default 12'
- '--no-progress 10'
steps:
- name: Retrieve nvm
shell: bash
run: |
unset npm_config_prefix
if [ "${{ matrix.npm-node-version }}" = "--lts" ]; then
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
else
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash
fi
. "$HOME/.nvm/nvm.sh"
nvm install ${{ matrix.npm-node-version }}
cygwin_matrix:
continue-on-error: true
permissions:
contents: none
name: 'Cygwin nvm install'
runs-on: windows-latest
steps:
- name: Install Cygwin
shell: bash
run: |
export SITE='https://mirror.clarkson.edu/cygwin/' # see https://archlinux.org/mirrors/clarkson.edu/1603/ for uptime status
export SITE='https://mirrors.kernel.org/sourceware/cygwin/'
export LOCALDIR="$(pwd)"
export ROOTDIR="$USERPROFILE\\cygwin"
export PACKAGES='bash,git,curl'
curl -fsSLo setup-x86_64.exe 'https://cygwin.com/setup-x86_64.exe'
./setup-x86_64.exe --disable-buggy-antivirus -q -s "$SITE" -l "$LOCALDIR" -R "$ROOTDIR" -P "$PACKAGES"
cat >~/setup.sh <<EOM
unset npm_config_prefix
export NVM_INSTALL_GITHUB_REPO="$NVM_INSTALL_GITHUB_REPO"
export NVM_INSTALL_VERSION="$NVM_INSTALL_VERSION"
export HOME="$(cygpath -u "$USERPROFILE")"
echo "HOME is $HOME"
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
ls -l $HOME/.nvm
. "$HOME/.nvm/nvm.sh"
nvm install --lts
nvm deactivate
rm -rf "$HOME/.nvm/nvm.sh"
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash
. "$HOME/.nvm/nvm.sh"
nvm install 9
EOM
- name: Retrieve nvm
shell: cmd
run: |
cd %USERPROFILE%\cygwin\bin
bash.exe "%USERPROFILE%\setup.sh"
wsl_matrix:
continue-on-error: true
name: 'WSL nvm install'
defaults:
run:
shell: wsl-bash {0}
runs-on: windows-latest
env:
WSLENV: NVM_INSTALL_GITHUB_REPO:NVM_INSTALL_VERSION:/p
strategy:
fail-fast: false
matrix:
wsl-distrib:
- Debian
# - Alpine # fails
- Ubuntu-20.04
- Ubuntu-18.04
npm-node-version:
- '--lts'
- '21'
- '18'
- '16'
- '14'
- '12'
- '10'
exclude:
- wsl-distrib: Ubuntu-18.04
npm-node-version: '--lts'
- wsl-distrib: Ubuntu-18.04
npm-node-version: '21'
- wsl-distrib: Ubuntu-18.04
npm-node-version: '18'
# node v24+ doesn't work on WSL1 (exec format error)
- wsl-distrib: Debian
npm-node-version: '--lts'
- wsl-distrib: Ubuntu-20.04
npm-node-version: '--lts'
method:
- ''
- 'script'
steps:
# For Ubuntu: install with packages directly
- if: matrix.wsl-distrib != 'Debian'
uses: Vampire/setup-wsl@v3
with:
distribution: ${{ matrix.wsl-distrib }}
additional-packages: bash git curl ca-certificates wget
# For Debian: install without packages first (apt-get update fails due to stale sources.list)
# see https://github.com/Vampire/setup-wsl/issues/76
- if: matrix.wsl-distrib == 'Debian'
uses: Vampire/setup-wsl@v3
with:
distribution: ${{ matrix.wsl-distrib }}
- if: matrix.wsl-distrib == 'Debian'
shell: 'wsl-bash {0}'
run: 'sed -i s/ftp.debian.org/archive.debian.org/ /etc/apt/sources.list'
- if: matrix.wsl-distrib == 'Debian'
name: 'Install packages with retries'
shell: 'wsl-bash {0}'
run: |
retry() {
local n=0
local max=3
local delay=5
while true; do
"$@" && break || {
n=$((n+1))
if [ $n -lt $max ]; then
echo "Command failed. Attempt $n/$max. Retrying in $delay seconds..."
sleep $delay
else
echo "Command failed after $max attempts."
return 1
fi
}
done
}
retry apt-get update
retry apt-get upgrade --yes
retry apt-get install --yes bash git curl ca-certificates wget
- name: Retrieve nvm on WSL
run: |
if [ -z "${{ matrix.method }}" ]; then
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
else
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD="${{matrix.method}}" bash
fi
. "$HOME/.nvm/nvm.sh"
nvm install ${{ matrix.npm-node-version }}
node -v
wsl_matrix_unofficial:
continue-on-error: true
name: 'WSL nvm install'
defaults:
run:
shell: wsl-bash {0}
runs-on: windows-latest
env:
WSLENV: NVM_INSTALL_GITHUB_REPO:NVM_INSTALL_VERSION:/p
NVM_NODEJS_ORG_MIRROR: https://unofficial-builds.nodejs.org/download/release
strategy:
fail-fast: false
matrix:
wsl-distrib:
- Alpine
npm-node-version:
- '--lts'
- '21'
- '18'
- '16'
- '14'
- '12'
- '11'
- '10'
method:
- ''
- 'script'
steps:
- uses: Vampire/setup-wsl@v3
with:
distribution: ${{ matrix.wsl-distrib }}
additional-packages: bash git curl ca-certificates wget
- name: Retrieve nvm on WSL
run: |
if [ -z "${{ matrix.method }}" ]; then
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
else
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD="${{matrix.method}}" bash
fi
. "$HOME/.nvm/nvm.sh"
NVM_NODEJS_ORG_MIRROR=${{ env.NVM_NODEJS_ORG_MIRROR }} nvm install ${{ matrix.npm-node-version }}
nvm_windows:
name: 'tests, on windows'
permissions:
contents: none
needs: [wsl_matrix, wsl_matrix_unofficial, cygwin_matrix, msys_matrix, msys_fail_install]
runs-on: ubuntu-latest
steps:
- run: true
================================================
FILE: .gitignore
================================================
# gitignore
HEAD
.cache
v*
alias
# For testing
test/bak
.urchin.log
.urchin_stdout
test/**/test_output
test/**/.nvmrc
node_modules/
npm-debug.log
.DS_Store
current
/default-packages
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
target/
================================================
FILE: .gitmodules
================================================
[submodule "test/fixtures/nvmrc"]
path = test/fixtures/nvmrc
url = git@github.com:nvm-sh/nvmrc.git
================================================
FILE: .mailmap
================================================
Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
================================================
FILE: .npmrc
================================================
package-lock=false
================================================
FILE: AGENTS.md
================================================
# nvm Coding Agent Instructions
This document provides guidance for AI coding agents when working with the Node Version Manager (nvm) codebase.
## Overview
nvm is a version manager for Node.js, implemented as a POSIX-compliant function that works across multiple shells (sh, dash, bash, ksh, zsh). The codebase is primarily written in shell script and emphasizes portability and compatibility.
### Core Architecture
- **Main script**: `nvm.sh` - Contains all core functionality and the main `nvm()` function
- **Installation script**: `install.sh` - Handles downloading and installing nvm itself
- **Execution wrapper**: `nvm-exec` - Allows running commands with specific Node.js versions
- **Bash completion**: `bash_completion` - Provides tab completion for bash users
- **Tests**: Comprehensive test suite in `test/` directory using the [urchin](https://www.npmjs.com/package/urchin) test framework
## Key Files and Their Purposes
### `nvm.sh`
The core functionality file containing:
- Main `nvm()` function (starts around line 3000)
- All internal helper functions (prefixed with `nvm_`)
- Command implementations for install, use, ls, etc.
- Shell compatibility logic
- POSIX compliance utilities
### `install.sh`
Handles nvm installation via curl/wget/git:
- Downloads nvm from GitHub
- Sets up directory structure
- Configures shell integration
- Supports both git clone and script download methods
### `nvm-exec`
Simple wrapper script that:
- Sources nvm.sh with `--no-use` flag
- Switches to specified Node version via `NODE_VERSION` env var or `.nvmrc`
- Executes the provided command with that Node version
## Top-Level nvm Commands and Internal Functions
### Core Commands
#### `nvm install [version]`
- **Internal functions**: `nvm_install_binary()`, `nvm_install_source()`, `nvm_download_artifact()`
- Downloads and installs specified Node.js version
- Automatically `nvm use`s that version after installation
- Supports LTS versions, version ranges, and built-in aliases (like `node`, `stable`) and user-defined aliases
- Can install from binary or compile from source
- When compiling from source, accepts additional arguments that are passed to the compilation task
#### `nvm use [version]`
- **Internal functions**: `nvm_resolve_alias()`, `nvm_version_path()`, `nvm_change_path()`
- Switches current shell to use specified Node.js version
- Updates PATH environment variable
- Supports `.nvmrc` file integration
#### `nvm ls [pattern]`
- **Internal functions**: `nvm_ls()`, `nvm_tree_contains_path()`
- Lists installed Node.js versions
- Supports pattern matching and filtering
- Shows current version and aliases
#### `nvm ls-remote [pattern]`
- **Internal functions**: `nvm_ls_remote()`, `nvm_download()`, `nvm_ls_remote_index_tab()`
- Lists available Node.js versions from nodejs.org and iojs.org, or the env-var-configured mirrors
- Supports LTS filtering and pattern matching
- Downloads version index on-demand
#### `nvm alias [name] [version]`
- **Internal functions**: `nvm_alias()`, `nvm_alias_path()`
- Creates text files containing the mapped version, named as the alias name
- Special aliases: `default`, `node`, `iojs`, `stable`, `unstable` (note: `stable` and `unstable` are deprecated, from node's pre-v1 release plan)
- Stored in `$NVM_DIR/alias/` directory
#### `nvm current`
- **Internal functions**: `nvm_ls_current()`
- Shows currently active Node.js version
- Returns "system" if using system Node.js
#### `nvm which [version]`
- **Internal functions**: `nvm_version_path()`, `nvm_resolve_alias()`
- Shows path to specified Node.js version
- Resolves aliases and version strings
### Utility Commands
#### `nvm cache clear|dir`
- Cache management for downloaded binaries and source code
- Clears or shows cache directory path
#### `nvm debug`
- Diagnostic information for troubleshooting
- Shows environment, tool versions, and paths
#### `nvm deactivate`
- Removes nvm modifications from current shell
- Restores original PATH
#### `nvm unload`
- Completely removes nvm from shell environment
- Unsets all nvm functions and variables
### Internal Function Categories
#### Version Resolution
- `nvm_resolve_alias()` - Resolves aliases to version numbers
- `nvm_version()` - Finds best matching local version
- `nvm_remote_version()` - Finds best matching remote version
- `nvm_normalize_version()` - Standardizes version strings
- `nvm_version_greater()` - Compares version numbers
- `nvm_version_greater_than_or_equal_to()` - Version comparison with equality
- `nvm_get_latest()` - Gets latest version from a list
#### Installation Helpers
- `nvm_install_binary()` - Downloads and installs precompiled binaries
- `nvm_install_source()` - Compiles Node.js from source
- `nvm_download_artifact()` - Downloads tarballs or binaries
- `nvm_compute_checksum()` - Verifies download integrity
- `nvm_checksum()` - Checksum verification wrapper
- `nvm_get_mirror()` - Gets appropriate download mirror
- `nvm_get_arch()` - Determines system architecture
#### Path Management
- `nvm_change_path()` - Updates PATH for version switching
- `nvm_strip_path()` - Removes nvm paths from PATH
- `nvm_version_path()` - Gets installation path for version
- `nvm_version_dir()` - Gets version directory name
- `nvm_prepend_path()` - Safely prepends to PATH
#### Shell Detection and Compatibility
- `nvm_is_zsh()` - Shell detection for zsh
- `nvm_is_iojs_version()` - Checks if version is io.js
- `nvm_get_os()` - Operating system detection
- `nvm_supports_source_options()` - Checks if shell supports source options
#### Network and Remote Operations
- `nvm_download()` - Generic download function
- `nvm_ls_remote()` - Lists remote versions
- `nvm_ls_remote_iojs()` - Lists remote io.js versions
- `nvm_ls_remote_index_tab()` - Parses remote version index
#### Utility Functions
- `nvm_echo()`, `nvm_err()` - Output functions
- `nvm_has()` - Checks if command exists
- `nvm_sanitize_path()` - Cleans sensitive data from paths
- `nvm_die_on_prefix()` - Validates npm prefix settings
- `nvm_ensure_default_set()` - Ensures default alias is set
- `nvm_auto()` - Automatic version switching from .nvmrc
#### Alias Management
- `nvm_alias()` - Creates or lists aliases
- `nvm_alias_path()` - Gets path to alias file
- `nvm_unalias()` - Removes aliases
- `nvm_resolve_local_alias()` - Resolves local aliases
#### Listing and Display
- `nvm_ls()` - Lists local versions
- `nvm_ls_current()` - Shows current version
- `nvm_tree_contains_path()` - Checks if path is in nvm tree
- `nvm_format_version()` - Formats version display
## Running Tests
### Test Framework
nvm uses the [urchin](https://www.npmjs.com/package/urchin) test framework for shell script testing.
### Test Structure
```
test/
├── fast/ # Quick unit tests
├── slow/ # Integration tests
├── sourcing/ # Shell sourcing tests
├── install_script/ # Installation script tests
├── installation_node/ # Node installation tests
├── installation_iojs/ # io.js installation tests
└── common.sh # Shared test utilities
```
### Running Tests
#### Install Dependencies
```bash
npm install # Installs urchin, semver, and replace tools
```
#### Run All Tests
```bash
npm test # Runs tests in current shell (sh, bash, dash, zsh, ksh)
make test # Runs tests in all supported shells (sh, bash, dash, zsh, ksh)
make test-sh # Runs tests only in sh
make test-bash # Runs tests only in bash
make test-dash # Runs tests only in dash
make test-zsh # Runs tests only in zsh
make test-ksh # Runs tests only in ksh
```
#### Run Specific Test Suites
```bash
make TEST_SUITE=fast test # Only fast tests
make TEST_SUITE=slow test # Only slow tests
make SHELLS=bash test # Only bash shell
```
#### Individual Test Execution
```bash
./test/fast/Unit\ tests/nvm_get_arch # Run single test (WARNING: This will exit/terminate your current shell session)
./node_modules/.bin/urchin test/fast/ # Run fast test suite
./node_modules/.bin/urchin 'test/fast/Unit tests/nvm_get_arch' # Run single test safely without shell termination
./node_modules/.bin/urchin test/slow/ # Run slow test suite
./node_modules/.bin/urchin test/sourcing/ # Run sourcing test suite
```
### Test Writing Guidelines
- Tests should work across all supported shells (sh, bash, dash, zsh, ksh)
- Define and use a `die()` function for test failures
- Clean up after tests in cleanup functions
- Mock external dependencies when needed
- Place mocks in `test/mocks/` directory
- Mock files should only be updated by the existing `update_test_mocks.sh` script, and any new mocks must be added to this script
## Shell Environment Setup
### Supported Shells
- **bash** - Full feature support
- **zsh** - Full feature support
- **dash** - Basic POSIX support
- **sh** - Basic POSIX support
- **ksh** - Limited support (experimental)
### Installing Shell Environments
#### Ubuntu/Debian
```bash
sudo apt-get update
sudo apt-get install bash zsh dash ksh
# sh is typically provided by dash or bash and is available by default
```
#### macOS
```bash
# bash and zsh are available by default, bash is not the default shell for new user accounts
# Install other shells via Homebrew
brew install dash ksh
# For actual POSIX sh (not bash), install mksh which provides a true POSIX sh
brew install mksh
```
#### Manual Shell Testing
```bash
# Test in specific shell
bash -c "source nvm.sh && nvm --version"
zsh -c "source nvm.sh && nvm --version"
dash -c ". nvm.sh && nvm --version"
sh -c ". nvm.sh && nvm --version" # On macOS: mksh -c ". nvm.sh && nvm --version"
ksh -c ". nvm.sh && nvm --version"
```
### Shell-Specific Considerations
- **zsh**: Requires basically any non-default zsh option to be temporarily unset to restore POSIX compliance
- **dash**: Limited feature set, avoid bash-specific syntax
- **ksh**: Some features may not work, primarily for compatibility testing
## CI Environment Details
### GitHub Actions Workflows
#### `.github/workflows/tests.yml`
- Runs test suite across multiple shells and test suites
- Uses `script` command for proper TTY simulation
- Matrix strategy covers shell × test suite combinations
- Excludes install_script tests from non-bash shells
#### `.github/workflows/shellcheck.yml`
- Lints all shell scripts using shellcheck
- Tests against multiple shell targets (bash, sh, dash, ksh)
- Note: zsh is not included due to [shellcheck limitations](https://github.com/koalaman/shellcheck/issues/809)
- Uses Homebrew to install latest shellcheck version
#### `.github/workflows/lint.yml`
- Runs additional linting and formatting checks
- Validates documentation and code style
### Travis CI (Legacy)
- Configured in `.travis.yml`
- Tests on multiple Ubuntu versions
- Installs shell environments via apt packages
### CI Test Execution
```bash
# Simulate CI environment locally
unset TRAVIS_BUILD_DIR # Disable Travis-specific logic
unset GITHUB_ACTIONS # Disable GitHub Actions logic
make test
```
## Setting Up shellcheck Locally
### Installation
#### macOS (Homebrew)
```bash
brew install shellcheck
```
#### Ubuntu/Debian
```bash
sudo apt-get install shellcheck
```
#### From Source
```bash
# Download from https://github.com/koalaman/shellcheck/releases
wget https://github.com/koalaman/shellcheck/releases/download/latest/shellcheck-latest.linux.x86_64.tar.xz
tar -xf shellcheck-latest.linux.x86_64.tar.xz
sudo cp shellcheck-latest/shellcheck /usr/local/bin/
```
### Usage
#### Lint Main Files
```bash
shellcheck -s bash nvm.sh
shellcheck -s bash install.sh
shellcheck -s bash nvm-exec
shellcheck -s bash bash_completion
```
#### Lint Across Shell Types
```bash
shellcheck -s sh nvm.sh # POSIX sh
shellcheck -s bash nvm.sh # Bash extensions
shellcheck -s dash nvm.sh # Dash compatibility
shellcheck -s ksh nvm.sh # Ksh compatibility
```
#### Common shellcheck Directives in nvm
- `# shellcheck disable=SC2039` - Allow bash extensions in POSIX mode
- `# shellcheck disable=SC2016` - Allow literal `$` in single quotes
- `# shellcheck disable=SC2001` - Allow sed usage instead of parameter expansion
- `# shellcheck disable=SC3043` - Allow `local` keyword (bash extension)
### Fixing shellcheck Issues
1. **Quoting**: Always quote variables: `"${VAR}"` instead of `$VAR`
2. **POSIX compliance**: Avoid bash-specific features in portable sections
3. **Array usage**: Use `set --` for positional parameters instead of arrays, which are not supported in POSIX
4. **Local variables**: Declared with `local FOO` and then initialized on the next line (the latter is for ksh support)
## Development Best Practices
### Code Style
- Use 2-space indentation
- Follow POSIX shell guidelines for portability
- Prefix internal functions with `nvm_`
- Use `nvm_echo` instead of `echo` for output
- Use `nvm_err` for error messages
### Compatibility
- Test changes across all supported shells
- Avoid bash-specific features in core functionality
- Use `nvm_is_zsh` to check when zsh-specific behavior is needed
- Mock external dependencies in tests
### Performance
- Cache expensive operations (like remote version lists)
- Use local variables to avoid scope pollution
- Minimize subprocess calls where possible
- Implement lazy loading for optional features
### Debugging
- Use `nvm debug` command for environment information
- Enable verbose output with `set -x` during development
- Test with `NVM_DEBUG=1` environment variable
- Check `$NVM_DIR/.cache` for cached data issues
## Common Gotchas
1. **PATH modification**: nvm modifies PATH extensively; be careful with restoration
2. **Shell sourcing**: nvm must be sourced, not executed as a script
3. **Version resolution**: Aliases, partial versions, and special keywords interact complexly
4. **Platform differences**: Handle differences between Linux, macOS, and other Unix systems
5. **Network dependencies**: Many operations require internet access for version lists
6. **Concurrent access**: Multiple shells can conflict when installing versions simultaneously
## Windows Support
nvm works on Windows via several compatibility layers:
### WSL2 (Windows Subsystem for Linux)
- Full nvm functionality available
- **Important**: Ensure you're using WSL2, not WSL1 - see [Microsoft's WSL2 installation guide](https://docs.microsoft.com/en-us/windows/wsl/install) for up-to-date instructions
- Install Ubuntu or other Linux distribution from Microsoft Store
- Follow Linux installation instructions within WSL2
### Cygwin
- POSIX-compatible environment for Windows
- Download Cygwin from [cygwin.com](https://www.cygwin.com/install.html) and run the installer
- During installation, include these packages: bash, curl, git, tar, and wget
- May require additional PATH configuration
### Git Bash (MSYS2)
- Comes with Git for Windows
- Limited functionality compared to full Linux environment
- Some features may not work due to path translation issues, including:
- Binary extraction paths may be incorrectly translated
- Symlink creation may fail
- Some shell-specific features may behave differently
- File permissions handling differs from Unix systems
### Setup Instructions for Windows
#### WSL2 (recommended)
1. Install WSL2 using the official Microsoft guide: https://docs.microsoft.com/en-us/windows/wsl/install
2. Install Ubuntu or preferred Linux distribution from Microsoft Store
3. Follow standard Linux installation within WSL2
#### Git Bash
1. Install Git for Windows (includes Git Bash) from https://git-scm.com/download/win
2. Open Git Bash terminal
3. Run nvm installation script
#### Cygwin
1. Download and install Cygwin from https://www.cygwin.com/install.html
2. Include bash, curl, git, tar, and wget packages during installation
3. Run nvm installation in Cygwin terminal
This guide should help AI coding agents understand the nvm codebase structure, testing procedures, and development environment setup requirements.
================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Code of Conduct
`nvm`, as a member project of the OpenJS Foundation, uses [Contributor Covenant v2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) as their code of conduct. The full text is included [below](#contributor-covenant-code-of-conduct) in English, and translations are available from the Contributor Covenant organisation:
- [contributor-covenant.org/translations](https://www.contributor-covenant.org/translations)
- [github.com/ContributorCovenant](https://github.com/ContributorCovenant/contributor_covenant/tree/release/content/version/2/1)
Refer to the sections on reporting and escalation in this document for the specific emails that can be used to report and escalate issues.
## Reporting
### Project Spaces
For reporting issues in spaces related to `nvm` please use the email `ljharb@gmail.com`. `nvm` handles CoC issues related to the spaces that it maintains. Projects maintainers commit to:
- maintain the confidentiality with regard to the reporter of an incident
- to participate in the path for escalation as outlined in the section on Escalation when required.
### Foundation Spaces
For reporting issues in spaces managed by the OpenJS Foundation, for example, repositories within the OpenJS organization, use the email `report@lists.openjsf.org`.
The Cross Project Council (CPC) is responsible for managing these reports and commits to:
- maintain the confidentiality with regard to the reporter of an incident
- to participate in the path for escalation as outlined in the section on Escalation when required.
## Escalation
The OpenJS Foundation maintains a Code of Conduct Panel (CoCP).
This is a foundation-wide team established to manage escalation when a reporter believes that a report to a member project or the CPC has not been properly handled.
In order to escalate to the CoCP send an email to `coc-escalation@lists.openjsf.org`.
For more information, refer to the full [Code of Conduct governance document](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/CODE_OF_CONDUCT.md).
---
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [@ljharb](ljharb@gmail.com).
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of actions.
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].
[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
================================================
FILE: CONTRIBUTING.md
================================================
# Contributing
:+1::tada: First off, thanks for taking the time to contribute to `nvm`! :tada::+1:
We love pull requests and issues, they're our favorite.
The following is a set of guidelines for contributing to `nvm` managed by [@LJHarb](https://github.com/ljharb), which is hosted on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
However, before submitting, please review the following:
# How Can I Contribute?
There are lots of ways to get involved. Here are some suggestions of things we'd love some help with.
## Resolving existing issues
You can consider helping out with issues already requiring attention - look for a "help wanted" label.
### How Do I Submit a (Good) Bug Report? :bug:
Explain the problem and include additional details to help maintainers reproduce the problem:
* **Use a clear and descriptive title** for the issue to identify the problem.
* **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining which command exactly you used in the terminal. When listing steps, **don't just say what you did, but explain how you did it**. For example, if you moved the cursor to the end of a line, explain if you used the mouse, or a keyboard shortcut or a command, and if so which one?
* **Provide specific examples to demonstrate the steps**. Include links to files or Github projects, or copy/pasteable snippets, which you use in those examples. If you're providing snippets in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines).
* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
* **Explain which behavior you expected to see instead and why.**
* **Provide as much context as possible** in order to help others verify and ultimately fix the issue. This includes giving us as much details as possible about your environment, so we can more easily confirm the problem.
## Documentation
We are happy to welcome contributions from anyone willing to improve documentation by adding missing information or making it more consistent and coherent.
# Dev Environment
Please refer to the [README](README.md) for complete instructions how to install, update, as well as troubleshoot `nvm` in your environment depending on your Operating System.
# Style Guide / Coding conventions
### Pull requests
#### Before creating a pull request
- Please include tests. Changes with tests will be merged very quickly.
- Please manually confirm that your changes work in `bash`, `sh`/`dash`, `ksh`, and `zsh`. Fast tests do run in these shells, but it's nice to manually verify also.
- Please maintain consistent whitespace - 2-space indentation, trailing newlines in all files, etc.
- Any time you make a change to your PR, please rebase freshly on top of the default branch. Nobody likes merge commits.
Even if you don't have all of these items covered, please still feel free to submit a PR/issue! Someone else may be inspired and volunteer to complete it for you.
#### How to create a pull request
Create a new branch
```
git checkout -b issue1234
```
Commit the changes to your branch, including a coherent commit message that follows our [standards](#commit-messages)
```
git commit -a
```
Before sending the pull request, make sure your code is running on the latest available code by rebasing onto the upstream source
```
git fetch upstream
git rebase upstream/main
```
Verify your changes
```
npm test
```
Push your changes
```
git push origin issue1234
```
Send the [pull request](https://docs.github.com/en/pull-requests), make requested changes, and get merged.
### Commit Messages
* Limit the first line of the commit message (message summary) to 72 characters or less.
* Use the present tense ("Add feature" not "Added feature") and imperative mood ("Move cursor to..." not "Moves cursor to...") when providing a description of what you did.
* If your PR addresses an issue, reference it in the body of the commit message.
* See the rest of the conventions [here](https://gist.github.com/ljharb/772b0334387a4bee89af24183114b3c7)
#### Commit message example
```
[Tag]: Short description of what you did
Longer description here if necessary
Fixes #1234
```
> **Note:** Add co-authors to your commit message for commits with multiple authors
```
Co-authored-by: Name Here <email@here>
```
# Code of Conduct
[Code of Conduct](https://github.com/nvm-sh/nvm/blob/HEAD/CODE_OF_CONDUCT.md)
# Where can I ask for help?
If you have any questions, please contact [@LJHarb](mailto:ljharb@gmail.com).
# Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
- The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
- The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
- The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
- I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
================================================
FILE: Dockerfile
================================================
# Dockerized nvm development environment
#
# This Dockerfile is for building nvm development environment only,
# not for any distribution/production usage.
#
# Please note that it'll use about 1.2 GB disk space and about 15 minutes to
# build this image, it depends on your hardware.
FROM ubuntu:22.04
LABEL maintainer="Peter Dave Hello <hsu@peterdavehello.org>"
LABEL name="nvm-dev-env"
LABEL version="latest"
# Set the SHELL to bash with pipefail option
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Prevent dialog during apt install
ENV DEBIAN_FRONTEND noninteractive
# ShellCheck version
ENV SHELLCHECK_VERSION=0.7.0
# Pick a Ubuntu apt mirror site for better speed
# ref: https://launchpad.net/ubuntu/+archivemirrors
ENV UBUNTU_APT_SITE ubuntu.cs.utah.edu
# Replace origin apt package site with the mirror site
RUN sed -E -i "s/([a-z]+.)?archive.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
RUN sed -i "s/security.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
# Install apt packages
RUN apt update && \
apt upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" && \
apt install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
coreutils \
util-linux \
bsdutils \
file \
openssl \
libssl-dev \
locales \
ca-certificates \
ssh \
wget \
patch \
sudo \
htop \
dstat \
vim \
tmux \
curl \
git \
jq \
zsh \
ksh \
gcc \
g++ \
xz-utils \
build-essential \
bash-completion && \
apt-get clean
RUN wget https://github.com/koalaman/shellcheck/releases/download/v$SHELLCHECK_VERSION/shellcheck-v$SHELLCHECK_VERSION.linux.x86_64.tar.xz -O- | \
tar xJvf - shellcheck-v$SHELLCHECK_VERSION/shellcheck && \
mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \
rmdir shellcheck-v$SHELLCHECK_VERSION
RUN shellcheck -V
# Set locale
RUN locale-gen en_US.UTF-8
# Print tool versions
RUN bash --version | head -n 1
RUN zsh --version
RUN ksh --version || true
RUN dpkg -s dash | grep ^Version | awk '{print $2}'
RUN git --version
RUN curl --version
RUN wget --version
# Add user "nvm" as non-root user
RUN useradd -ms /bin/bash nvm
# Copy and set permission for nvm directory
COPY . /home/nvm/.nvm/
RUN chown nvm:nvm -R "/home/nvm/.nvm"
# Set sudoer for "nvm"
RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
# Switch to user "nvm" from now
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
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$BASH_ENV"
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' >> "$BASH_ENV"
# nodejs and tools
RUN nvm install node
RUN npm install -g doctoc urchin eclint dockerfile_lint
RUN npm install --prefix "$HOME/.nvm/"
# Set WORKDIR to nvm directory
WORKDIR /home/nvm/.nvm
ENTRYPOINT ["/bin/bash"]
================================================
FILE: GOVERNANCE.md
================================================
# `nvm` Project Governance
## Maintainers
- [@ljharb](https://github.com/ljharb)
Maintainers are responsible for issue/PR triage, feature additions, maintenance, bugfixes, security fixes, releases, promoting existing contributors to maintainers, managing repo and CI configuration, etc.
## Contributors
Anyone who contributes code or content or time, via issues or pull requests or otherwise. Contributors do not have any additional permissions on the project.
================================================
FILE: LICENSE.md
================================================
The MIT License (MIT)
Copyright (c) 2010 Tim Caswell
Copyright (c) 2014 Jordan Harband
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================
FILE: Makefile
================================================
# Since we rely on paths relative to the makefile location, abort if make isn't being run from there.
$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))
# Note: With Travis CI:
# - the path to urchin is passed via the command line.
# - the other utilities are NOT needed, so we skip the test for their existence.
URCHIN := urchin
ifeq ($(findstring /,$(URCHIN)),) # urchin path was NOT passed in.
# Add the local npm packages' bin folder to the PATH, so that `make` can find them, when invoked directly.
# Note that rather than using `$(npm bin)` the 'node_modules/.bin' path component is hard-coded, so that invocation works even from an environment
# where npm is (temporarily) unavailable due to having deactivated an nvm instance loaded into the calling shell in order to avoid interference with tests.
export PATH := $(shell printf '%s' "$$PWD/node_modules/.bin:$$PATH")
# The list of all supporting utilities, installed with `npm install`.
UTILS := $(URCHIN) replace semver
# Make sure that all required utilities can be located.
UTIL_CHECK := $(or $(shell PATH="$(PATH)" which $(UTILS) >/dev/null && echo 'ok'),$(error Did you forget to run `npm install` after cloning the repo? At least one of the required supporting utilities not found: $(UTILS)))
endif
# The files that need updating when incrementing the version number.
VERSIONED_FILES := nvm.sh install.sh README.md package.json
# Define all shells to test with. Can be overridden with `make SHELLS=... <target>`.
SHELLS := sh bash dash zsh # ksh (#574)
# Generate 'test-<shell>' target names from specified shells.
# The embedded shell names are extracted on demand inside the recipes.
SHELL_TARGETS := $(addprefix test-,$(SHELLS))
# Define the default test suite(s). This can be overridden with `make TEST_SUITE=<...> <target>`.
# Test suites are the names of subfolders of './test'.
TEST_SUITE := $(shell find ./test/* -type d -prune -exec basename {} \;)
# Default target (by virtue of being the first non '.'-prefixed in the file).
.PHONY: _no-target-specified
_no-target-specified:
$(error Please specify the target to make - `make list` shows targets. Alternatively, use `npm test` to run the default tests; `npm run` shows all tests)
# Lists all targets defined in this makefile.
.PHONY: list
list:
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
# Set of test-<shell> targets; each runs the specified test suites for a single shell.
# Note that preexisting NVM_* variables are unset to avoid interfering with tests, except when running the Travis tests (where NVM_DIR must be passed in and the env. is assumed to be pristine).
.PHONY: $(SHELL_TARGETS)
$(SHELL_TARGETS):
@shell='$@'; shell=$${shell##*-}; \
which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \
printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
[ -z "$$TRAVIS_BUILD_DIR" ] && [ -z "$$GITHUB_ACTIONS" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
for suite in $(TEST_SUITE); do \
echo "Running test suite: $$suite"; \
$(URCHIN) -f -s $$shell test/$$suite || exit; \
done
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
.PHONY: test
test: $(SHELL_TARGETS)
.PHONY: _ensure-tag
_ensure-tag:
ifndef TAG
$(error Please invoke with `make TAG=<new-version> release`, where <new-version> is either an increment specifier (patch, minor, major, prepatch, preminor, premajor, prerelease), or an explicit major.minor.patch version number)
endif
# Ensures there are version tags in repository
.PHONY: _ensure-current-version
_ensure-current-version:
ifeq ($(shell git tag),$(printf ''))
@git fetch --tags
endif
# Ensures that the git workspace is clean.
.PHONY: _ensure-clean
_ensure-clean:
@[ -z "$$(git status --porcelain --untracked-files=no || echo err)" ] || { echo "Workspace is not clean; please commit changes first." >&2; exit 2; }
# Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`.
.PHONY: release
release: _ensure-tag _ensure-clean _ensure-current-version
@old_ver=`git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*'` || { echo "Failed to determine current version." >&2; exit 1; }; old_ver=$${old_ver#v}; \
new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \
if printf "$$new_ver" | grep -q '^[0-9]'; then \
semver "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be major.minor.patch' >&2; exit 2; }; \
semver -r "> $$old_ver" "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be HIGHER than current one.' >&2; exit 2; } \
else \
new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \
fi; \
printf "=== Bumping version **$$old_ver** to **$$new_ver** before committing and tagging:\n=== TYPE 'proceed' TO PROCEED, anything else to abort: " && read response && [ "$$response" = 'proceed' ] || { echo 'Aborted.' >&2; exit 2; }; \
replace "$$old_ver" "$$new_ver" $(VERSIONED_FILES) && \
git commit -m "v$$new_ver" $(VERSIONED_FILES) && \
git tag -a "v$$new_ver"
================================================
FILE: PROJECT_CHARTER.md
================================================
# `nvm` Charter
nvm is a version manager for Node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and Windows WSL.
## Section 0: Guiding Principles
The `nvm` project is part of the [OpenJS Foundation][openjs foundation], which operates transparently, openly, collaboratively, and ethically. Project proposals, timelines, and status must not merely be open, but also easily visible to outsiders.
## Section 1: Scope
`nvm` is a node version manager, focused on making it easy to install and manage multiple Node.js versions. Any features related to managing the installation and removal of Node.js on any node-supported platform are potentially in scope.
## Section 2: Relationship with OpenJS Foundation CPC.
Technical leadership for the projects within the [OpenJS Foundation][openjs foundation] is delegated to the projects through their project charters by the [OpenJS Foundation Cross-Project Council](https://openjsf.org/about/governance/) (CPC). In the case of the `nvm` project, it is delegated to the [`nvm` Maintainers](README.md#maintainers) (the “Maintainers”). The OpenJS Foundation's business leadership is the Board of Directors (the “Board”).
This `nvm` Charter reflects a carefully constructed balanced role for the Maintainers and the CPC in the governance of the OpenJS Foundation. The charter amendment process is for the Maintainers to propose changes using simple majority of the full Maintainers, the proposed changes being subject to review and approval by the CPC. The CPC may additionally make amendments to the project charter at any time, though the CPC will not interfere with day-to-day discussions, votes or meetings of the Maintainers.
### 2.1 Other Formal Project Relationships
Section Intentionally Left Blank
## Section 3: `nvm`'s Maintainers Governing Body
`nvm` is governed by its [maintainers](README.md#maintainers).
## Section 4: Roles & Responsibilities
The roles and responsibilities of `nvm`'s Maintainers are described in [GOVERNANCE.md](./GOVERNANCE.md).
### Section 4.1 Project Operations & Management
Section Intentionally Left Blank
### Section 4.2: Decision-making, Voting, and/or Elections
Section Intentionally Left Blank
### Section 4.3: Other Project Roles
Section Intentionally Left Blank
## Section 5: Definitions
- *Contributors*: contribute code or other artifacts, but do not have the right to commit to the codebase. Contributors work with the project’s maintainers to have code committed to the code base. A Contributor may be promoted to a Maintainer by the Maintainers. Contributors should rarely be encumbered by the Maintainers and never by the CPC or OpenJS Foundation Board.
- *Maintainers*: Contributors with any kind of decision-making authority in the project.
[openjs foundation]: https://openjsf.org
================================================
FILE: README.md
================================================
<a href="https://github.com/nvm-sh/logos">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nvm-sh/logos/HEAD/nvm-logo-white.svg" />
<img src="https://raw.githubusercontent.com/nvm-sh/logos/HEAD/nvm-logo-color.svg" height="50" alt="nvm project logo" />
</picture>
</a>
# Node Version Manager [][3] [][4] [](https://bestpractices.dev/projects/684)
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of Contents
- [Intro](#intro)
- [About](#about)
- [Installing and Updating](#installing-and-updating)
- [Install & Update Script](#install--update-script)
- [Additional Notes](#additional-notes)
- [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 macOS](#troubleshooting-on-macos)
- [Ansible](#ansible)
- [Verify Installation](#verify-installation)
- [Important Notes](#important-notes)
- [Git Install](#git-install)
- [Manual Install](#manual-install)
- [Manual Upgrade](#manual-upgrade)
- [Usage](#usage)
- [Long-term Support](#long-term-support)
- [Migrating Global Packages While Installing](#migrating-global-packages-while-installing)
- [Default Global Packages From File While Installing](#default-global-packages-from-file-while-installing)
- [io.js](#iojs)
- [System Version of Node](#system-version-of-node)
- [Listing Versions](#listing-versions)
- [Setting Custom Colors](#setting-custom-colors)
- [Persisting custom colors](#persisting-custom-colors)
- [Suppressing colorized output](#suppressing-colorized-output)
- [Restoring PATH](#restoring-path)
- [Set default node version](#set-default-node-version)
- [Use a mirror of node binaries](#use-a-mirror-of-node-binaries)
- [Pass Authorization header to mirror](#pass-authorization-header-to-mirror)
- [.nvmrc](#nvmrc)
- [Deeper Shell Integration](#deeper-shell-integration)
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
- [bash](#bash)
- [zsh](#zsh)
- [fish](#fish)
- [Running Tests](#running-tests)
- [Environment variables](#environment-variables)
- [Bash Completion](#bash-completion)
- [Usage](#usage-1)
- [Compatibility Issues](#compatibility-issues)
- [Installing nvm on Alpine Linux](#installing-nvm-on-alpine-linux)
- [Alpine Linux 3.13+](#alpine-linux-313)
- [Alpine Linux 3.5 - 3.12](#alpine-linux-35---312)
- [Uninstalling / Removal](#uninstalling--removal)
- [Manual Uninstall](#manual-uninstall)
- [Docker For Development Environment](#docker-for-development-environment)
- [Problems](#problems)
- [macOS Troubleshooting](#macos-troubleshooting)
- [WSL Troubleshooting](#wsl-troubleshooting)
- [Maintainers](#maintainers)
- [Project Support](#project-support)
- [Enterprise Support](#enterprise-support)
- [License](#license)
- [Copyright notice](#copyright-notice)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Intro
`nvm` allows you to quickly install and use different versions of node via the command line.
**Example:**
```sh
$ nvm use 16
Now using node v16.9.1 (npm v7.21.1)
$ node -v
v16.9.1
$ nvm use 14
Now using node v14.18.0 (npm v6.14.15)
$ node -v
v14.18.0
$ nvm install 12
Now using node v12.22.6 (npm v6.14.5)
$ node -v
v12.22.6
```
Simple as that!
## About
nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be installed per-user, and invoked per-shell. `nvm` works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and [windows WSL](https://github.com/nvm-sh/nvm#important-notes).
<a id="installation-and-update"></a>
<a id="install-script"></a>
## Installing and Updating
### Install & Update Script
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
```
```sh
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
```
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bashrc`, `~/.bash_profile`, `~/.zshrc`, or `~/.profile`). If you find the install script is updating the wrong profile file, set the `$PROFILE` env var to the profile file’s path, and then rerun the installation script.
<a id="profile_snippet"></a>
```sh
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
```
#### Additional Notes
- If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there.</sub>
- You can add `--no-use` to the end of the above script to postpone using `nvm` until you manually [`use`](#usage) it:
```sh
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
```
- You can customize the install source, directory, profile, and version using the `NVM_SOURCE`, `NVM_DIR`, `PROFILE`, and `NODE_VERSION` variables.
Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not contain a trailing slash.
- The installer can use `git`, `curl`, or `wget` to download `nvm`, whichever is available.
- 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.4/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.40.4/install.sh | PROFILE="${BASH_ENV}" bash
RUN echo node > .nvmrc
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.4/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.4
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
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.
Alternatively, you can run the following commands for the different shells on the command line:
*bash*: `source ~/.bashrc`
*zsh*: `source ~/.zshrc`
*ksh*: `. ~/.profile`
These should pick up the `nvm` command.
#### Troubleshooting on macOS
Since OS X 10.9, `/usr/bin/git` has been preset by Xcode command line tools, which means we can't properly detect if Git is installed or not. You need to manually install the Xcode command line tools before running the install script, otherwise, it'll fail. (see [#1782](https://github.com/nvm-sh/nvm/issues/1782))
If you get `nvm: command not found` after running the install script, one of the following might be the reason:
- Since macOS 10.15, the default shell is `zsh` and nvm will look for `.zshrc` to update, none is installed by default. Create one with `touch ~/.zshrc` and run the install script again.
- If you use bash, the previous default shell, your system may not have `.bash_profile` or `.bashrc` files where the command is set up. Create one of them with `touch ~/.bash_profile` or `touch ~/.bashrc` and run the install script again. Then, run `. ~/.bash_profile` or `. ~/.bashrc` to pick up the `nvm` command.
- You have previously used `bash`, but you have `zsh` installed. You need to manually add [these lines](#manual-install) to `~/.zshrc` and run `. ~/.zshrc`.
- You might need to restart your terminal instance or run `. ~/.nvm/nvm.sh`. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration.
- If the above didn't help, you might need to restart your terminal instance. Try opening a new tab/window in your terminal and retry.
If the above doesn't fix the problem, you may try the following:
- If you use bash, it may be that your `.bash_profile` (or `~/.profile`) does not source your `~/.bashrc` properly. You could fix this by adding `source ~/<your_profile_file>` to it or following the next step below.
- Try adding [the snippet from the install section](#profile_snippet), that finds the correct nvm directory and loads nvm, to your usual profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
- For more information about this issue and possible workarounds, please [refer here](https://github.com/nvm-sh/nvm/issues/576)
**Note** For Macs with the Apple Silicon chip, node started offering **arm64** arch Darwin packages since v16.0.0 and experimental **arm64** support when compiling from source since v14.17.0. If you are facing issues installing node using `nvm`, you may want to update to one of those versions or later.
#### Ansible
You can use a task:
```yaml
- name: Install nvm
ansible.builtin.shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
```
### Verify Installation
To verify that nvm has been installed, do:
```sh
command -v nvm
```
which should output `nvm` if the installation was successful. Please note that `which nvm` will not work, since `nvm` is a sourced shell function, not an executable binary.
**Note:** 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.
### Important Notes
If you're running a system without prepackaged binary available, which means you're going to install node or io.js from its source code, you need to make sure your system has a C++ compiler. For OS X, Xcode will work, for Debian/Ubuntu based GNU/Linux, the `build-essential` and `libssl-dev` packages work.
**Note:** `nvm` also supports Windows in some cases. It should work through WSL (Windows Subsystem for Linux) depending on the version of WSL. It should also work with [GitBash](https://gitforwindows.org/) (MSYS) or [Cygwin](https://cygwin.com). Otherwise, for Windows, a few alternatives exist, which are neither supported nor developed by us:
- [nvm-windows](https://github.com/coreybutler/nvm-windows)
- [nodist](https://github.com/marcelklehr/nodist)
- [nvs](https://github.com/jasongin/nvs)
**Note:** `nvm` does not support [Fish] either (see [#303](https://github.com/nvm-sh/nvm/issues/303)). Alternatives exist, which are neither supported nor developed by us:
- [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
- [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
- [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.
**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:
- [[#900] [Bug] node on FreeBSD may need to be patched](https://github.com/nvm-sh/nvm/issues/900)
- [nodejs/node#3716](https://github.com/nodejs/node/issues/3716)
**Note:** On OS X, if you do not have Xcode installed and you do not wish to download the ~4.3GB file, you can install the `Command Line Tools`. You can check out this blog post on how to just that:
- [How to Install Command Line Tools in OS X Mavericks & Yosemite (Without Xcode)](https://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/)
**Note:** On OS X, if you have/had a "system" node installed and want to install modules globally, keep in mind that:
- When using `nvm` you do not need `sudo` to globally install a module with `npm -g`, so instead of doing `sudo npm install -g grunt`, do instead `npm install -g grunt`
- If you have an `~/.npmrc` file, make sure it does not contain any `prefix` settings (which is not compatible with `nvm`)
- You can (but should not?) keep your previous "system" node install, but `nvm` will only be available to your user account (the one used to install nvm). This might cause version mismatches, as other users will be using `/usr/local/lib/node_modules/*` VS your user account using `~/.nvm/versions/node/vX.X.X/lib/node_modules/*`
Homebrew installation is not supported. If you have issues with homebrew-installed `nvm`, please `brew uninstall` it, and install it using the instructions below, before filing an issue.
**Note:** If you're using `zsh` you can easily install `nvm` as a zsh plugin. Install [`zsh-nvm`](https://github.com/lukechilds/zsh-nvm) and run `nvm upgrade` to upgrade ([you can set](https://github.com/lukechilds/zsh-nvm#auto-use) `NVM_AUTO_USE=true` to have it automatically detect and use `.nvmrc` files).
**Note:** Git versions before v1.7 may face a problem of cloning `nvm` source from GitHub via https protocol, and there is also different behavior of git before v1.6, and git prior to [v1.17.10](https://github.com/git/git/commit/5a7d5b683f869d3e3884a89775241afa515da9e7) can not clone tags, so the minimum required git version is v1.7.10. If you are interested in the problem we mentioned here, please refer to GitHub's [HTTPS cloning errors](https://help.github.com/articles/https-cloning-errors/) article.
### Git Install
If you have `git` installed (requires git v1.7.10+):
1. clone this repo in the root of your user profile
- `cd ~/` from anywhere then `git clone https://github.com/nvm-sh/nvm.git .nvm`
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.4`
1. activate `nvm` by sourcing it from your shell: `. ./nvm.sh`
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
(you may have to add to more than one of the above files)
```sh
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
```
### Manual Install
For a fully manual install, execute the following lines to first clone the `nvm` repository into `$HOME/.nvm`, and then load `nvm`:
```sh
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"
```
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
(you may have to add to more than one of the above files)
```sh
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
```
### Manual Upgrade
For manual upgrade with `git` (requires git v1.7.10+):
1. change to the `$NVM_DIR`
1. pull down the latest changes
1. check out the latest version
1. activate the new version
```sh
(
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"
```
## Usage
To download, compile, and install the latest release of node, do this:
```sh
nvm install node # "node" is an alias for the latest version
```
To install a specific version of node:
```sh
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc
```
To set an alias:
```sh
nvm alias my_alias v14.4.0
```
Make sure that your alias does not contain any spaces or slashes.
The first version installed becomes the default. New shells will start with the default version of node (e.g., `nvm alias default`).
You can list available versions using `ls-remote`:
```sh
nvm ls-remote
```
And then in any new shell just use the installed version:
```sh
nvm use node
```
Or you can just run it:
```sh
nvm run node --version
```
Or, you can run any arbitrary command in a subshell with the desired version of node:
```sh
nvm exec 4.2 node --version
```
You can also get the path to the executable to where it was installed:
```sh
nvm which 12.22
```
In place of a version pointer like "14.7" or "16.3" or "12.22.1", you can use the following special default aliases with `nvm install`, `nvm use`, `nvm run`, `nvm exec`, `nvm which`, etc:
- `node`: this installs the latest version of [`node`](https://nodejs.org/en/)
- `iojs`: this installs the latest version of [`io.js`](https://iojs.org/en/)
- `stable`: this alias is deprecated, and only truly applies to `node` `v0.12` and earlier. Currently, this is an alias for `node`.
- `unstable`: this alias points to `node` `v0.11` - the last "unstable" node release, since post-1.0, all node versions are stable. (in SemVer, versions communicate breakage, not stability).
### Long-term Support
Node has a [schedule](https://github.com/nodejs/Release#release-schedule) for long-term support (LTS) You can reference LTS versions in aliases and `.nvmrc` files with the notation `lts/*` for the latest LTS, and `lts/argon` for LTS releases from the "argon" line, for example. In addition, the following commands support LTS arguments:
- `nvm install --lts` / `nvm install --lts=argon` / `nvm install 'lts/*'` / `nvm install lts/argon`
- `nvm uninstall --lts` / `nvm uninstall --lts=argon` / `nvm uninstall 'lts/*'` / `nvm uninstall lts/argon`
- `nvm use --lts` / `nvm use --lts=argon` / `nvm use 'lts/*'` / `nvm use lts/argon`
- `nvm exec --lts` / `nvm exec --lts=argon` / `nvm exec 'lts/*'` / `nvm exec lts/argon`
- `nvm run --lts` / `nvm run --lts=argon` / `nvm run 'lts/*'` / `nvm run lts/argon`
- `nvm ls-remote --lts` / `nvm ls-remote --lts=argon` `nvm ls-remote 'lts/*'` / `nvm ls-remote lts/argon`
- `nvm version-remote --lts` / `nvm version-remote --lts=argon` / `nvm version-remote 'lts/*'` / `nvm version-remote lts/argon`
Any time your local copy of `nvm` connects to https://nodejs.org, it will re-create the appropriate local aliases for all available LTS lines. These aliases (stored under `$NVM_DIR/alias/lts`), are managed by `nvm`, and you should not modify, remove, or create these files - expect your changes to be undone, and expect meddling with these files to cause bugs that will likely not be supported.
To get the latest LTS version of node and migrate your existing installed packages, use:
```sh
nvm install --reinstall-packages-from=current 'lts/*'
```
### Migrating Global Packages While Installing
If you want to install a new version of Node.js and migrate npm packages from a previous version:
```sh
nvm install --reinstall-packages-from=node node
```
This will first use "nvm version node" to identify the current version you're migrating packages from. Then it resolves the new version to install from the remote server and installs it. Lastly, it runs "nvm reinstall-packages" to reinstall the npm packages from your prior version of Node to the new one.
You can also install and migrate npm packages from specific versions of Node like this:
```sh
nvm install --reinstall-packages-from=5 6
nvm install --reinstall-packages-from=iojs v4.2
```
Note that reinstalling packages _explicitly does not update the npm version_ — this is to ensure that npm isn't accidentally upgraded to a broken version for the new node version.
To update npm at the same time add the `--latest-npm` flag, like this:
```sh
nvm install --reinstall-packages-from=default --latest-npm 'lts/*'
```
or, you can at any time run the following command to get the latest supported npm version on the current node version:
```sh
nvm install-latest-npm
```
If you've already gotten an error to the effect of "npm does not support Node.js", you'll need to (1) revert to a previous node version (`nvm ls` & `nvm use <your latest _working_ version from the ls>`), (2) delete the newly created node version (`nvm uninstall <your _broken_ version of node from the ls>`), then (3) rerun your `nvm install` with the `--latest-npm` flag.
### Offline Install
If you've previously downloaded a node version (or it's still in the cache), you can install it without any network access using the `--offline` flag:
```sh
nvm install --offline 14.7.0
```
This resolves versions using only locally installed versions and cached downloads. It will not attempt to download anything. This is useful in air-gapped environments, on planes, or when you want to avoid network latency.
You can combine `--offline` with `--lts` to install the latest cached LTS version (as long as LTS aliases have been populated by a prior `nvm ls-remote --lts`):
```sh
nvm install --offline --lts
```
### Default Global Packages From File While Installing
If you have a list of default packages you want installed every time you install a new version, we support that too -- just add the package names, one per line, to the file `$NVM_DIR/default-packages`. You can add anything npm would accept as a package argument on the command line.
```sh
# $NVM_DIR/default-packages
rimraf
object-inspect@1.0.2
stevemao/left-pad
```
### io.js
> [!WARNING]
> io.js was a [fork of Node.js](https://en.wikipedia.org/wiki/Node.js#History), created in 2014 and merged back in 2015. io.js shipped v1, v2, and v3 release lines; post-merge, node.js began releasing with v4.
If you want to install io.js:
```sh
nvm install iojs
```
If you want to install a new version of io.js and migrate npm packages from a previous version:
```sh
nvm install --reinstall-packages-from=iojs iojs
```
The same guidelines mentioned for migrating npm packages in node are applicable to io.js.
### System Version of Node
If you want to use the system-installed version of node, you can use the special default alias "system":
```sh
nvm use system
nvm run system --version
```
### Listing Versions
If you want to see what versions are installed:
```sh
nvm ls
```
If you want to see what versions are available to install:
```sh
nvm ls-remote
```
### Setting Custom Colors
You can set five colors that will be used to display version and alias information. These colors replace the default colors.
Initial colors are: g b y r e
Color codes:
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
```sh
nvm set-colors rgBcm
```
#### Persisting custom colors
If you want the custom colors to persist after terminating the shell, export the `NVM_COLORS` variable in your shell profile. For example, if you want to use cyan, magenta, green, bold red and bold yellow, add the following line:
```sh
export NVM_COLORS='cmgRY'
```
#### Suppressing colorized output
`nvm help (or -h or --help)`, `nvm ls`, `nvm ls-remote` and `nvm alias` usually produce colorized output. You can disable colors with the `--no-colors` option (or by setting the environment variable `TERM=dumb`):
```sh
nvm ls --no-colors
nvm help --no-colors
TERM=dumb nvm ls
```
### Restoring PATH
To restore your PATH, you can deactivate it:
```sh
nvm deactivate
```
### Set default node version
To set a default Node version to be used in any new shell, use the alias 'default':
```sh
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
```
### Use a mirror of node binaries
To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
```sh
export NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
nvm install node
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 4.2
```
To use a mirror of the io.js binaries, set `$NVM_IOJS_ORG_MIRROR`:
```sh
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
```
`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs. Note that using `nvm` in multiple shell tabs with this environment variable enabled can cause race conditions.
#### Pass Authorization header to mirror
To pass an Authorization header through to the mirror url, set `$NVM_AUTH_HEADER`
```sh
NVM_AUTH_HEADER="Bearer secret-token" nvm install node
```
### .nvmrc
You can create a `.nvmrc` file containing a node version number (or any other string that `nvm` understands; see `nvm --help` for details) in the project root directory (or any parent directory).
Afterwards, `nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will use the version specified in the `.nvmrc` file if no version is supplied on the command line.
For example, to make nvm default to the latest 5.9 release, the latest LTS version, or the latest node version for the current directory:
```sh
$ echo "5.9" > .nvmrc
$ echo "lts/*" > .nvmrc # to default to the latest LTS version
$ echo "node" > .nvmrc # to default to the latest version
```
[NB these examples assume a POSIX-compliant shell version of `echo`. If you use a Windows `cmd` development environment, eg the `.nvmrc` file is used to configure a remote Linux deployment, then keep in mind the `"`s will be copied leading to an invalid file. Remove them.]
Then when you run nvm use:
```sh
$ nvm use
Found '/path/to/project/.nvmrc' with version <5.9>
Now using node v5.9.1 (npm v3.7.3)
```
Running nvm install will also switch over to the correct version, but if the correct node version isn't already installed, it will install it for you.
```sh
$ 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)
```
`nvm use` et. al. will traverse directory structure upwards from the current directory looking for the `.nvmrc` file. In other words, running `nvm use` et. al. in any subdirectory of a directory with an `.nvmrc` will result in that `.nvmrc` being utilized.
The contents of a `.nvmrc` file **must** contain precisely one `<version>` (as described by `nvm --help`) followed by a newline. `.nvmrc` files may also have comments. The comment delimiter is `#`, and it and any text after it, as well as blank lines, and leading and trailing white space, will be ignored when parsing.
Key/value pairs using `=` are also allowed and ignored, but are reserved for future use, and may cause validation errors in the future.
Run [`npx nvmrc`](https://npmjs.com/nvmrc) to validate an `.nvmrc` file. If that tool’s results do not agree with nvm, one or the other has a bug - please file an issue.
### Deeper Shell Integration
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).
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.
#### Calling `nvm use` automatically in a directory with a `.nvmrc` file
In your profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`), add the following to `nvm use` whenever you enter a new directory:
##### bash
Put the following at the end of your `$HOME/.bashrc`:
```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
```
This alias would search 'up' from your current directory in order to detect a `.nvmrc` file. If it finds it, it will switch to that version; if not, it will use the default version.
##### zsh
This shell function will install (if needed) and `nvm use` the specified Node version when an `.nvmrc` is found, and `nvm use default` otherwise.
Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you enter a directory that contains an
`.nvmrc` file with a string telling nvm which node to `use`:
```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
```
After saving the file, run `source ~/.zshrc` to reload the configuration with the latest changes made.
##### fish
This requires that you have [bass](https://github.com/edc/bass) installed.
```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
```
## Running Tests
Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
npm install
There are slow tests and fast tests. The slow tests do things like install node
and check that the right versions are used. The fast tests fake this to test
things like aliases and uninstalling. From the root of the nvm git repository,
run the fast tests like this:
npm run test/fast
Run the slow tests like this:
npm run test/slow
Run all of the tests like this:
npm test
Nota bene: Avoid running nvm while the tests are running.
## Environment variables
nvm exposes the following environment variables:
- `NVM_DIR` - nvm's installation directory.
- `NVM_BIN` - where node, npm, and global packages for the active version of node are installed.
- `NVM_INC` - node's include file directory (useful for building C/C++ addons for node).
- `NVM_CD_FLAGS` - used to maintain compatibility with zsh.
- `NVM_RC_VERSION` - version from .nvmrc file if being used.
Additionally, nvm modifies `PATH`, and, if present, `MANPATH` and `NODE_PATH` when changing versions.
## Bash Completion
To activate, you need to source `bash_completion`:
```sh
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion
```
Put the above sourcing line just below the sourcing line for nvm in your profile (`.bashrc`, `.bash_profile`).
### Usage
nvm:
> `$ nvm` <kbd>Tab</kbd>
```sh
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
```
nvm alias:
> `$ nvm alias` <kbd>Tab</kbd>
```sh
default iojs lts/* lts/argon lts/boron lts/carbon lts/dubnium lts/erbium node stable unstable
```
> `$ nvm alias my_alias` <kbd>Tab</kbd>
```sh
v10.22.0 v12.18.3 v14.8.0
```
nvm use:
> `$ nvm use` <kbd>Tab</kbd>
```
my_alias default v10.22.0 v12.18.3 v14.8.0
```
nvm uninstall:
> `$ nvm uninstall` <kbd>Tab</kbd>
```
my_alias default v10.22.0 v12.18.3 v14.8.0
```
## 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))
The following are known to cause issues:
Inside `~/.npmrc`:
```sh
prefix='some/path'
```
Environment Variables:
```sh
$NPM_CONFIG_PREFIX
$PREFIX
```
Shell settings:
```sh
set -e
```
## Installing nvm on Alpine Linux
In order to provide the best performance (and other optimizations), nvm will download and install pre-compiled binaries for Node (and npm) when you run `nvm install X`. The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, CentOS, RedHat et al).
Alpine Linux, unlike mainstream/traditional Linux distributions, is based on [BusyBox](https://www.busybox.net/), a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - [musl](https://www.musl-libc.org/). This makes binary programs built for such mainstream/traditional incompatible with Alpine Linux, thus we cannot simply `nvm install X` on Alpine Linux and expect the downloaded binary to run correctly - you'll likely see "...does not exist" errors if you try that.
There is a `-s` flag for `nvm install` which requests nvm download Node source and compile it locally.
If installing nvm on Alpine Linux *is* still what you want or need to do, you should be able to achieve this by running the following from you Alpine Linux shell, depending on which version you are using:
### Alpine Linux 3.13+
```sh
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.4/install.sh | bash
```
### Alpine Linux 3.5 - 3.12
```sh
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.4/install.sh | bash
```
_Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (**These are all versions on the main branch**). Alpine 3.5 - 3.12 required the package `python2` to build NodeJS, as they are older versions to build. Alpine 3.13+ requires `python3` to successfully build newer NodeJS versions, but you can use `python2` with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script._
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
As a potential alternative, @mhart (a Node contributor) has some [Docker images for Alpine Linux with Node and optionally, npm, pre-installed](https://github.com/mhart/alpine-node).
<a id="removal"></a>
## Uninstalling / Removal
### Manual Uninstall
To remove `nvm` manually, execute the following:
First, use `nvm unload` to remove the nvm command from your terminal session and delete the installation directory:
```sh
$ nvm_dir="${NVM_DIR:-~/.nvm}"
$ nvm unload
$ rm -rf "$nvm_dir"
```
Edit `~/.bashrc` (or other shell resource config) and remove the lines below:
```sh
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
```
## Docker For Development Environment
To make the development and testing work easier, we have a Dockerfile for development usage, which is based on Ubuntu 18.04 base image, prepared with essential and useful tools for `nvm` development, to build the docker image of the environment, run the docker command at the root of `nvm` repository:
```sh
$ docker build -t nvm-dev .
```
This will package your current nvm repository with our pre-defined development environment into a docker image named `nvm-dev`, once it's built with success, validate your image via `docker images`:
```sh
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nvm-dev latest 9ca4c57a97d8 7 days ago 650 MB
```
If you got no error message, now you can easily involve in:
```sh
$ docker run -h nvm-dev -it nvm-dev
nvm@nvm-dev:~/.nvm$
```
Please note that it'll take about 8 minutes to build the image and the image size would be about 650MB, so it's not suitable for production usage.
For more information and documentation about docker, please refer to its official website:
- https://www.docker.com/
- https://docs.docker.com/
## Problems
- If you try to install a node version and the installation fails, be sure to run `nvm cache clear` to delete cached node downloads, or you might get an error like the following:
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
- Where's my `sudo node`? Check out [#43](https://github.com/nvm-sh/nvm/issues/43)
- After the v0.8.6 release of node, nvm tries to install from binary packages. But in some systems, the official binary packages don't work due to incompatibility of shared libs. In such cases, use `-s` option to force install from source:
```sh
nvm install -s 0.8.6
```
- If setting the `default` alias does not establish the node version in new shells (i.e. `nvm current` yields `system`), ensure that the system's node `PATH` is set before the `nvm.sh` source line in your shell profile (see [#658](https://github.com/nvm-sh/nvm/issues/658))
## macOS Troubleshooting
**nvm node version not found in vim shell**
If you set node version to a version other than your system node version `nvm use 6.2.1` and open vim and run `:!node -v` you should see `v6.2.1` if you see your system version `v0.12.7`. You need to run:
```shell
sudo chmod ugo-x /usr/libexec/path_helper
```
More on this issue in [dotphiles/dotzsh](https://github.com/dotphiles/dotzsh#mac-os-x).
**nvm is not compatible with the npm config "prefix" option**
Some solutions for this issue can be found [here](https://github.com/nvm-sh/nvm/issues/1245)
There is one more edge case causing this issue, and that's a **mismatch between the `$HOME` path and the user's home directory's actual name**.
You have to make sure that the user directory name in `$HOME` and the user directory name you'd see from running `ls /Users/` **are capitalized the same way** ([See this issue](https://github.com/nvm-sh/nvm/issues/2261)).
To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548)
[1]: https://github.com/nvm-sh/nvm.git
[2]: https://github.com/nvm-sh/nvm/blob/v0.40.4/install.sh
[3]: https://github.com/nvm-sh/nvm/actions/workflows/tests-fast.yml
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.4
[Urchin]: https://git.sdf.org/tlevine/urchin
[Fish]: https://fishshell.com
**Homebrew makes zsh directories insecure**
```shell
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]? y
```
Homebrew causes insecure directories like `/usr/local/share/zsh/site-functions` and `/usr/local/share/zsh`. This is **not** an `nvm` problem - it is a homebrew problem. Refer [here](https://github.com/zsh-users/zsh-completions/issues/680) for some solutions related to the issue.
**Macs with Apple Silicon chips**
Experimental support for the Apple Silicon chip architecture was added in node.js v15.3 and full support was added in v16.0.
Because of this, if you try to install older versions of node as usual, you will probably experience either compilation errors when installing node or out-of-memory errors while running your code.
So, if you want to run a version prior to v16.0 on an Apple Silicon Mac, it may be best to compile node targeting the `x86_64` Intel architecture so that Rosetta 2 can translate the `x86_64` processor instructions to ARM-based Apple Silicon instructions.
Here's what you will need to do:
- Install Rosetta, if you haven't already done so
```sh
$ softwareupdate --install-rosetta
```
You might wonder, "how will my Apple Silicon Mac know to use Rosetta for a version of node compiled for an Intel chip?".
If an executable contains only Intel instructions, macOS will automatically use Rosetta to translate the instructions.
- Open a shell that's running using Rosetta
```sh
$ arch -x86_64 zsh
```
Note: This same thing can also be accomplished by finding the Terminal or iTerm App in Finder, right clicking, selecting "Get Info", and then checking the box labeled "Open using Rosetta".
Note: This terminal session is now running in `zsh`.
If `zsh` is not the shell you typically use, `nvm` may not be `source`'d automatically like it probably is for your usual shell through your dotfiles.
If that's the case, make sure to source `nvm`.
```sh
$ source "${NVM_DIR}/nvm.sh"
```
- Install whatever older version of node you are interested in. Let's use 12.22.1 as an example.
This will fetch the node source code and compile it, which will take several minutes.
```sh
$ nvm install v12.22.1 --shared-zlib
```
Note: You're probably curious why `--shared-zlib` is included.
There's a bug in recent versions of Apple's system `clang` compiler.
If one of these broken versions is installed on your system, the above step will likely still succeed even if you didn't include the `--shared-zlib` flag.
However, later, when you attempt to `npm install` something using your old version of node.js, you will see `incorrect data check` errors.
If you want to avoid the possible hassle of dealing with this, include that flag.
For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.476)
- Exit back to your native shell.
```sh
$ exit
$ arch
arm64
```
Note: If you selected the box labeled "Open using Rosetta" rather than running the CLI command in the second step, you will see `i386` here.
Unless you have another reason to have that box selected, you can deselect it now.
- Check to make sure the architecture is correct. `x64` is the abbreviation for `x86_64`, which is what you want to see.
```sh
$ node -p process.arch
x64
```
Now you should be able to use node as usual.
## WSL Troubleshooting
If you've encountered this error on WSL-2:
```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/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
```
It may be due to your antivirus, VPN, or other reasons.
Where you can `ping 8.8.8.8` while you can't `ping google.com`
This could simply be solved by running this in your root directory:
```sh
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
```
This deletes your `resolv.conf` file that is automatically generated when you run WSL, creates a new file and puts `nameserver 8.8.8.8`, then creates a `wsl.conf` file and adds `[network]` and `generateResolveConf = false` to prevent auto-generation of that file.
You can check the contents of the file by running:
```sh
cat /etc/resolv.conf
```
## Maintainers
Currently, the sole maintainer is [@ljharb](https://github.com/ljharb) - more maintainers are quite welcome, and we hope to add folks to the team over time. [Governance](./GOVERNANCE.md) will be re-evaluated as the project evolves.
## Project Support
Only the latest version (v0.40.4 at this time) is supported.
## Enterprise Support
If you are unable to update to the latest version of `nvm`, our [partners](https://openjsf.org/ecosystem-sustainability-program) provide commercial security fixes for all unsupported versions:
- [HeroDevs Never-Ending Support](https://www.herodevs.com/support?utm_source=OpenJS&utm_medium=Link&utm_campaign=nvm_openjs)
## License
See [LICENSE.md](./LICENSE.md).
## Copyright notice
Copyright [OpenJS Foundation](https://openjsf.org) and `nvm` contributors. All rights reserved. The [OpenJS Foundation](https://openjsf.org) has registered trademarks and uses trademarks. For a list of trademarks of the [OpenJS Foundation](https://openjsf.org), please see our [Trademark Policy](https://trademark-policy.openjsf.org/) and [Trademark List](https://trademark-list.openjsf.org/). Trademarks and logos not indicated on the [list of OpenJS Foundation trademarks](https://trademark-list.openjsf.org) are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
[The OpenJS Foundation](https://openjsf.org/) | [Terms of Use](https://terms-of-use.openjsf.org/) | [Privacy Policy](https://privacy-policy.openjsf.org/) | [Bylaws](https://bylaws.openjsf.org/) | [Code of Conduct](https://code-of-conduct.openjsf.org) | [Trademark Policy](https://trademark-policy.openjsf.org/) | [Trademark List](https://trademark-list.openjsf.org/) | [Cookie Policy](https://www.linuxfoundation.org/cookies/)
================================================
FILE: ROADMAP.md
================================================
# nvm Road Map
This is a list of the primary features planned for `nvm`:
- [x] Rewriting installation code paths to support installing `io.js` and `node` `v4+` [from source](https://github.com/nvm-sh/nvm/issues/1188).
- This will include [reusing previously downloaded tarballs](https://github.com/nvm-sh/nvm/issues/1193) that match checksums, which is a nice performance and bandwidth bonus.
- [ ] Adding opt-in environment variable support to list, download, and install `node` [release candidates](https://github.com/nvm-sh/nvm/issues/779), and [nightly builds](https://github.com/nvm-sh/nvm/issues/1053).
- [ ] [`nvm update`](https://github.com/nvm-sh/nvm/issues/400): the ability to autoupdate `nvm` itself
- [ ] [v1.0.0](https://github.com/nvm-sh/nvm/milestone/1), including updating the [nvm on npm](https://github.com/nvm-sh/nvm/issues/304) to auto-install nvm properly
================================================
FILE: bash_completion
================================================
#!/usr/bin/env bash
# bash completion for Node Version Manager (NVM)
if ! command -v nvm &> /dev/null; then
return
fi
__nvm_generate_completion() {
declare current_word
current_word="${COMP_WORDS[COMP_CWORD]}"
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$1" -- "${current_word}"))
return 0
}
__nvm_commands() {
declare current_word
declare command
current_word="${COMP_WORDS[COMP_CWORD]}"
COMMANDS='
help install uninstall use run exec
alias unalias reinstall-packages
current list ls list-remote ls-remote
install-latest-npm
cache deactivate unload
version version-remote which'
if [ ${#COMP_WORDS[@]} == 4 ]; then
command="${COMP_WORDS[COMP_CWORD - 2]}"
case "${command}" in
alias) __nvm_installed_nodes ;;
esac
else
case "${current_word}" in
-*) __nvm_options ;;
*) __nvm_generate_completion "${COMMANDS}" ;;
esac
fi
}
__nvm_options() {
OPTIONS=''
__nvm_generate_completion "${OPTIONS}"
}
__nvm_installed_nodes() {
__nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)"
}
__nvm_aliases() {
declare aliases
aliases=""
if [ -d "${NVM_DIR}/alias" ]; then
aliases="$(command cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")"
fi
echo "${aliases} node stable unstable iojs"
}
__nvm_alias() {
__nvm_generate_completion "$(__nvm_aliases)"
}
__nvm() {
declare previous_word
previous_word="${COMP_WORDS[COMP_CWORD - 1]}"
case "${previous_word}" in
use | run | exec | ls | list | uninstall) __nvm_installed_nodes ;;
alias | unalias) __nvm_alias ;;
*) __nvm_commands ;;
esac
return 0
}
# complete is a bash builtin, but recent versions of ZSH come with a function
# called bashcompinit that will create a complete in ZSH. If the user is in
# ZSH, load and run bashcompinit before calling the complete function.
if [[ -n ${ZSH_VERSION-} ]]; then
# First calling compinit (only if not called yet!)
# and then bashcompinit as mentioned by zsh man page.
if ! command -v compinit > /dev/null; then
autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
compinit -u
else
compinit
fi
fi
autoload -U +X bashcompinit && bashcompinit
fi
complete -o default -F __nvm nvm
================================================
FILE: install.sh
================================================
#!/usr/bin/env bash
{ # this ensures the entire script is downloaded #
nvm_has() {
type "$1" > /dev/null 2>&1
}
nvm_echo() {
command printf %s\\n "$*" 2>/dev/null
}
if [ -z "${BASH_VERSION}" ] || [ -n "${ZSH_VERSION}" ]; then
# shellcheck disable=SC2016
nvm_echo >&2 'Error: the install instructions explicitly say to pipe the install script to `bash`; please follow them'
exit 1
fi
nvm_grep() {
GREP_OPTIONS='' command grep "$@"
}
nvm_default_install_dir() {
[ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm"
}
nvm_install_dir() {
if [ -n "$NVM_DIR" ]; then
printf %s "${NVM_DIR}"
else
nvm_default_install_dir
fi
}
nvm_latest_version() {
nvm_echo "v0.40.4"
}
nvm_profile_is_bash_or_zsh() {
local TEST_PROFILE
TEST_PROFILE="${1-}"
case "${TEST_PROFILE-}" in
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc" | *"/.zprofile")
return
;;
*)
return 1
;;
esac
}
#
# Outputs the location to NVM depending on:
# * The availability of $NVM_SOURCE
# * The presence of $NVM_INSTALL_GITHUB_REPO
# * The method used ("script" or "git" in the script, defaults to "git")
# NVM_SOURCE always takes precedence unless the method is "script-nvm-exec"
#
nvm_source() {
local NVM_GITHUB_REPO
NVM_GITHUB_REPO="${NVM_INSTALL_GITHUB_REPO:-nvm-sh/nvm}"
if [ "${NVM_GITHUB_REPO}" != 'nvm-sh/nvm' ]; then
{ nvm_echo >&2 "$(cat)" ; } << EOF
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE REPO IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
The default repository for this install is \`nvm-sh/nvm\`,
but the environment variables \`\$NVM_INSTALL_GITHUB_REPO\` is
currently set to \`${NVM_GITHUB_REPO}\`.
If this is not intentional, interrupt this installation and
verify your environment variables.
EOF
fi
local NVM_VERSION
NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}"
local NVM_METHOD
NVM_METHOD="$1"
local NVM_SOURCE_URL
NVM_SOURCE_URL="$NVM_SOURCE"
if [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/nvm-exec"
elif [ "_$NVM_METHOD" = "_script-nvm-bash-completion" ]; then
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/bash_completion"
elif [ -z "$NVM_SOURCE_URL" ]; then
if [ "_$NVM_METHOD" = "_script" ]; then
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/nvm.sh"
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_REPO}.git"
else
nvm_echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
return 1
fi
fi
nvm_echo "$NVM_SOURCE_URL"
}
#
# Node.js version to install
#
nvm_node_version() {
nvm_echo "$NODE_VERSION"
}
nvm_download() {
if nvm_has "curl"; then
curl --fail --compressed -q "$@"
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
-e 's/--compressed //' \
-e 's/--fail //' \
-e 's/-L //' \
-e 's/-I /--server-response /' \
-e 's/-s /-q /' \
-e 's/-sS /-nv /' \
-e 's/-o /-O /' \
-e 's/-C - /-c /')
# shellcheck disable=SC2086
eval wget $ARGS
fi
}
install_nvm_from_git() {
local INSTALL_DIR
INSTALL_DIR="$(nvm_install_dir)"
local NVM_VERSION
NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}"
if [ -n "${NVM_INSTALL_VERSION:-}" ]; then
# Check if version is an existing ref
if command git ls-remote "$(nvm_source "git")" "$NVM_VERSION" | nvm_grep -q "$NVM_VERSION" ; then
:
# Check if version is an existing changeset
elif ! nvm_download -o /dev/null "$(nvm_source "script-nvm-exec")"; then
nvm_echo >&2 "Failed to find '$NVM_VERSION' version."
exit 1
fi
fi
local fetch_error
if [ -d "$INSTALL_DIR/.git" ]; then
# Updating repo
nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"
command printf '\r=> '
fetch_error="Failed to update nvm with $NVM_VERSION, run 'git fetch' in $INSTALL_DIR yourself."
else
fetch_error="Failed to fetch origin with $NVM_VERSION. Please report this!"
nvm_echo "=> Downloading nvm from git to '$INSTALL_DIR'"
command printf '\r=> '
mkdir -p "${INSTALL_DIR}"
if [ "$(ls -A "${INSTALL_DIR}")" ]; then
# Initializing repo
command git init "${INSTALL_DIR}" || {
nvm_echo >&2 'Failed to initialize nvm repo. Please report this!'
exit 2
}
command git --git-dir="${INSTALL_DIR}/.git" remote add origin "$(nvm_source)" 2> /dev/null \
|| command git --git-dir="${INSTALL_DIR}/.git" remote set-url origin "$(nvm_source)" || {
nvm_echo >&2 'Failed to add remote "origin" (or set the URL). Please report this!'
exit 2
}
else
# Cloning repo
command git clone -o origin "$(nvm_source)" --depth=1 "${INSTALL_DIR}" || {
nvm_echo >&2 'Failed to clone nvm repo. Please report this!'
exit 2
}
fi
fi
# Try to fetch tag
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin tag "$NVM_VERSION" --depth=1 2>/dev/null; then
:
# Fetch given version
elif ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin "$NVM_VERSION" --depth=1; then
nvm_echo >&2 "$fetch_error"
exit 1
fi
command git -c advice.detachedHead=false --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout -f --quiet FETCH_HEAD || {
nvm_echo >&2 "Failed to checkout the given version $NVM_VERSION. Please report this!"
exit 2
}
if [ -n "$(command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" show-ref refs/heads/master)" ]; then
if command git --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet 2>/dev/null; then
command git --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet -D master >/dev/null 2>&1
else
nvm_echo >&2 "Your version of git is out of date. Please update it!"
command git --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch -D master >/dev/null 2>&1
fi
fi
nvm_echo "=> Compressing and cleaning up git repository"
if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" reflog expire --expire=now --all; then
nvm_echo >&2 "Your version of git is out of date. Please update it!"
fi
if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" gc --auto --aggressive --prune=now ; then
nvm_echo >&2 "Your version of git is out of date. Please update it!"
fi
return
}
#
# Automatically install Node.js
#
nvm_install_node() {
local NODE_VERSION_LOCAL
NODE_VERSION_LOCAL="$(nvm_node_version)"
if [ -z "$NODE_VERSION_LOCAL" ]; then
return 0
fi
nvm_echo "=> Installing Node.js version $NODE_VERSION_LOCAL"
nvm install "$NODE_VERSION_LOCAL"
local CURRENT_NVM_NODE
CURRENT_NVM_NODE="$(nvm_version current)"
if [ "$(nvm_version "$NODE_VERSION_LOCAL")" == "$CURRENT_NVM_NODE" ]; then
nvm_echo "=> Node.js version $NODE_VERSION_LOCAL has been successfully installed"
else
nvm_echo >&2 "Failed to install Node.js $NODE_VERSION_LOCAL"
fi
}
install_nvm_as_script() {
local INSTALL_DIR
INSTALL_DIR="$(nvm_install_dir)"
local NVM_SOURCE_LOCAL
NVM_SOURCE_LOCAL="$(nvm_source script)"
local NVM_EXEC_SOURCE
NVM_EXEC_SOURCE="$(nvm_source script-nvm-exec)"
local NVM_BASH_COMPLETION_SOURCE
NVM_BASH_COMPLETION_SOURCE="$(nvm_source script-nvm-bash-completion)"
# Downloading to $INSTALL_DIR
mkdir -p "$INSTALL_DIR"
if [ -f "$INSTALL_DIR/nvm.sh" ]; then
nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update the script"
else
nvm_echo "=> Downloading nvm as script to '$INSTALL_DIR'"
fi
nvm_download -s "$NVM_SOURCE_LOCAL" -o "$INSTALL_DIR/nvm.sh" || {
nvm_echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'"
return 1
} &
nvm_download -s "$NVM_EXEC_SOURCE" -o "$INSTALL_DIR/nvm-exec" || {
nvm_echo >&2 "Failed to download '$NVM_EXEC_SOURCE'"
return 2
} &
nvm_download -s "$NVM_BASH_COMPLETION_SOURCE" -o "$INSTALL_DIR/bash_completion" || {
nvm_echo >&2 "Failed to download '$NVM_BASH_COMPLETION_SOURCE'"
return 2
} &
for job in $(jobs -p | command sort)
do
wait "$job" || return $?
done
chmod a+x "$INSTALL_DIR/nvm-exec" || {
nvm_echo >&2 "Failed to mark '$INSTALL_DIR/nvm-exec' as executable"
return 3
}
}
nvm_try_profile() {
if [ -z "${1-}" ] || [ ! -f "${1}" ]; then
return 1
fi
nvm_echo "${1}"
}
#
# Detect profile file if not specified as environment variable
# (eg: PROFILE=~/.myprofile)
# The echo'ed path is guaranteed to be an existing file
# Otherwise, an empty string is returned
#
nvm_detect_profile() {
if [ "${PROFILE-}" = '/dev/null' ]; then
# the user has specifically requested NOT to have nvm touch their profile
return
fi
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
nvm_echo "${PROFILE}"
return
fi
local DETECTED_PROFILE
DETECTED_PROFILE=''
if [ "${SHELL#*bash}" != "$SHELL" ]; then
if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
if [ -f "${ZDOTDIR:-${HOME}}/.zshrc" ]; then
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zshrc"
elif [ -f "${ZDOTDIR:-${HOME}}/.zprofile" ]; then
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zprofile"
fi
fi
if [ -z "$DETECTED_PROFILE" ]; then
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zprofile" ".zshrc"
do
if DETECTED_PROFILE="$(nvm_try_profile "${ZDOTDIR:-${HOME}}/${EACH_PROFILE}")"; then
break
fi
done
fi
if [ -n "$DETECTED_PROFILE" ]; then
nvm_echo "$DETECTED_PROFILE"
fi
}
#
# Check whether the user has any globally-installed npm modules in their system
# Node, and warn them if so.
#
nvm_check_global_modules() {
local NPM_COMMAND
NPM_COMMAND="$(command -v npm 2>/dev/null)" || return 0
[ -n "${NVM_DIR}" ] && [ -z "${NPM_COMMAND%%"$NVM_DIR"/*}" ] && return 0
local NPM_VERSION
NPM_VERSION="$(npm --version)"
NPM_VERSION="${NPM_VERSION:--1}"
[ "${NPM_VERSION%%[!-0-9]*}" -gt 0 ] || return 0
local NPM_GLOBAL_MODULES
NPM_GLOBAL_MODULES="$(
npm list -g --depth=0 |
command sed -e '/ npm@/d' -e '/ (empty)$/d'
)"
local MODULE_COUNT
MODULE_COUNT="$(
command printf %s\\n "$NPM_GLOBAL_MODULES" |
command sed -ne '1!p' | # Remove the first line
wc -l | command tr -d ' ' # Count entries
)"
if [ "${MODULE_COUNT}" != '0' ]; then
# shellcheck disable=SC2016
nvm_echo '=> You currently have modules installed globally with `npm`. These will no'
# shellcheck disable=SC2016
nvm_echo '=> longer be linked to the active version of Node when you install a new node'
# shellcheck disable=SC2016
nvm_echo '=> with `nvm`; and they may (depending on how you construct your `$PATH`)'
# shellcheck disable=SC2016
nvm_echo '=> override the binaries of modules installed with `nvm`:'
nvm_echo
command printf %s\\n "$NPM_GLOBAL_MODULES"
nvm_echo '=> If you wish to uninstall them at a later point (or re-install them under your'
# shellcheck disable=SC2016
nvm_echo '=> `nvm` node installs), you can remove them from the system Node as follows:'
nvm_echo
nvm_echo ' $ nvm use system'
nvm_echo ' $ npm uninstall -g a_module'
nvm_echo
fi
}
nvm_do_install() {
if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then
if [ -e "${NVM_DIR}" ]; then
nvm_echo >&2 "File \"${NVM_DIR}\" has the same name as installation directory."
exit 1
fi
if [ "${NVM_DIR}" = "$(nvm_default_install_dir)" ]; then
mkdir "${NVM_DIR}"
else
nvm_echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment."
exit 1
fi
fi
# Disable the optional which check, https://www.shellcheck.net/wiki/SC2230
# shellcheck disable=SC2230
if nvm_has xcode-select && [ "$(xcode-select -p >/dev/null 2>/dev/null ; echo $?)" = '2' ] && [ "$(which git)" = '/usr/bin/git' ] && [ "$(which curl)" = '/usr/bin/curl' ]; then
nvm_echo >&2 'You may be on a Mac, and need to install the Xcode Command Line Developer Tools.'
# shellcheck disable=SC2016
nvm_echo >&2 'If so, run `xcode-select --install` and try again. If not, please report this!'
exit 1
fi
if [ -z "${METHOD}" ]; then
# Autodetect install method
if nvm_has git; then
install_nvm_from_git
elif nvm_has curl || nvm_has wget; then
install_nvm_as_script
else
nvm_echo >&2 'You need git, curl, or wget to install nvm'
exit 1
fi
elif [ "${METHOD}" = 'git' ]; then
if ! nvm_has git; then
nvm_echo >&2 "You need git to install nvm"
exit 1
fi
install_nvm_from_git
elif [ "${METHOD}" = 'script' ]; then
if ! nvm_has curl && ! nvm_has wget; then
nvm_echo >&2 "You need curl or wget to install nvm"
exit 1
fi
install_nvm_as_script
else
nvm_echo >&2 "The environment variable \$METHOD is set to \"${METHOD}\", which is not recognized as a valid installation method."
exit 1
fi
nvm_echo
local NVM_PROFILE
NVM_PROFILE="$(nvm_detect_profile)"
local PROFILE_INSTALL_DIR
PROFILE_INSTALL_DIR="$(nvm_install_dir | command sed "s:^$HOME:\$HOME:")"
SOURCE_STR="\\nexport NVM_DIR=\"${PROFILE_INSTALL_DIR}\"\\n[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\" # This loads nvm\\n"
# shellcheck disable=SC2016
COMPLETION_STR='[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion\n'
BASH_OR_ZSH=false
if [ "${PROFILE-}" = '/dev/null' ] ; then
# the user has specifically requested NOT to have nvm touch their profile
echo
elif [ -z "${NVM_PROFILE-}" ] ; then
local TRIED_PROFILE
if [ -n "${PROFILE}" ]; then
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
fi
nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zprofile, ~/.zshrc, and ~/.profile."
nvm_echo "=> Create one of them and run this script again"
nvm_echo " OR"
nvm_echo "=> Append the following lines to the correct file yourself:"
command printf "${SOURCE_STR}"
nvm_echo
else
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then
BASH_OR_ZSH=true
fi
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
nvm_echo "=> Appending nvm source string to $NVM_PROFILE"
command printf "${SOURCE_STR}" >> "$NVM_PROFILE"
else
nvm_echo "=> nvm source string already in ${NVM_PROFILE}"
fi
# shellcheck disable=SC2016
if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
nvm_echo "=> Appending bash_completion source string to $NVM_PROFILE"
command printf "$COMPLETION_STR" >> "$NVM_PROFILE"
else
nvm_echo "=> bash_completion source string already in ${NVM_PROFILE}"
fi
fi
if ${BASH_OR_ZSH} && [ -z "${NVM_PROFILE-}" ] ; then
nvm_echo "=> Please also append the following lines to the if you are using bash/zsh shell:"
command printf "${COMPLETION_STR}"
fi
# Source nvm
# shellcheck source=/dev/null
\. "$(nvm_install_dir)/nvm.sh"
nvm_check_global_modules
nvm_install_node
nvm_reset
nvm_echo "=> Close and reopen your terminal to start using nvm or run the following to use it now:"
command printf "${SOURCE_STR}"
if ${BASH_OR_ZSH} ; then
command printf "${COMPLETION_STR}"
fi
}
#
# Unsets the various functions defined
# during the execution of the install script
#
nvm_reset() {
unset -f nvm_has nvm_install_dir nvm_latest_version nvm_profile_is_bash_or_zsh \
nvm_source nvm_node_version nvm_download install_nvm_from_git nvm_install_node \
install_nvm_as_script nvm_try_profile nvm_detect_profile nvm_check_global_modules \
nvm_do_install nvm_reset nvm_default_install_dir nvm_grep
}
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install
} # this ensures the entire script is downloaded #
================================================
FILE: nvm-exec
================================================
#!/usr/bin/env bash
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
unset NVM_CD_FLAGS
# shellcheck disable=SC1090,SC1091
\. "$DIR/nvm.sh" --no-use
if [ -n "$NODE_VERSION" ]; then
nvm use "$NODE_VERSION" > /dev/null || exit 127
else
nvm_rc_version > /dev/null && nvm_ensure_version_installed "$NVM_RC_VERSION";
if ! nvm use >/dev/null 2>&1; then
echo "No NODE_VERSION provided; no .nvmrc file found" >&2
exit 127
fi
fi
exec "$@"
================================================
FILE: nvm.sh
================================================
# Node Version Manager
# Implemented as a POSIX-compliant function
# Should work on sh, dash, bash, ksh, zsh
# To use source this file from your bash profile
#
# Implemented by Tim Caswell <tim@creationix.com>
# with much bash help from Matthew Ranney
# "local" warning, quote expansion warning, sed warning, `local` warning
# shellcheck disable=SC2039,SC2016,SC2001,SC3043
{ # this ensures the entire script is downloaded #
# shellcheck disable=SC3028
NVM_SCRIPT_SOURCE="$_"
nvm_is_zsh() {
[ -n "${ZSH_VERSION-}" ]
}
nvm_stdout_is_terminal() {
[ -t 1 ]
}
nvm_echo() {
command printf %s\\n "$*" 2>/dev/null
}
nvm_echo_with_colors() {
command printf %b\\n "$*" 2>/dev/null
}
nvm_cd() {
\cd "$@"
}
nvm_err() {
>&2 nvm_echo "$@"
}
nvm_err_with_colors() {
>&2 nvm_echo_with_colors "$@"
}
nvm_grep() {
GREP_OPTIONS='' command grep "$@"
}
nvm_has() {
type "${1-}" >/dev/null 2>&1
}
nvm_has_non_aliased() {
nvm_has "${1-}" && ! nvm_is_alias "${1-}"
}
nvm_is_alias() {
# this is intentionally not "command alias" so it works in zsh.
\alias "${1-}" >/dev/null 2>&1
}
nvm_command_info() {
local COMMAND
local INFO
COMMAND="${1}"
if type "${COMMAND}" | nvm_grep -q hashed; then
INFO="$(type "${COMMAND}" | command sed -E 's/\(|\)//g' | command awk '{print $4}')"
elif type "${COMMAND}" | nvm_grep -q aliased; then
# shellcheck disable=SC2230
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4="" ;print }' | command sed -e 's/^\ *//g' -Ee "s/\`|'//g"))"
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is an alias for"; then
# shellcheck disable=SC2230
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4=$5="" ;print }' | command sed 's/^\ *//g'))"
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is /"; then
INFO="$(type "${COMMAND}" | command awk '{print $3}')"
else
INFO="$(type "${COMMAND}")"
fi
nvm_echo "${INFO}"
}
nvm_has_colors() {
local NVM_NUM_COLORS
if nvm_has tput; then
NVM_NUM_COLORS="$(command tput -T "${TERM:-vt100}" colors)"
fi
[ -t 1 ] && [ "${NVM_NUM_COLORS:--1}" -ge 8 ] && [ "${NVM_NO_COLORS-}" != '--no-colors' ]
}
nvm_curl_libz_support() {
curl -V 2>/dev/null | nvm_grep "^Features:" | nvm_grep -q "libz"
}
nvm_curl_use_compression() {
nvm_curl_libz_support && nvm_version_greater_than_or_equal_to "$(nvm_curl_version)" 7.21.0
}
nvm_get_latest() {
local NVM_LATEST_URL
local CURL_COMPRESSED_FLAG
if nvm_has "curl"; then
if nvm_curl_use_compression; then
CURL_COMPRESSED_FLAG="--compressed"
fi
NVM_LATEST_URL="$(curl ${CURL_COMPRESSED_FLAG:-} -q -w "%{url_effective}\\n" -L -s -S https://latest.nvm.sh -o /dev/null)"
elif nvm_has "wget"; then
NVM_LATEST_URL="$(wget -q https://latest.nvm.sh --server-response -O /dev/null 2>&1 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')"
else
nvm_err 'nvm needs curl or wget to proceed.'
return 1
fi
if [ -z "${NVM_LATEST_URL}" ]; then
nvm_err "https://latest.nvm.sh did not redirect to the latest release on GitHub"
return 2
fi
nvm_echo "${NVM_LATEST_URL##*/}"
}
nvm_download() {
if nvm_has "curl"; then
local CURL_COMPRESSED_FLAG=""
local CURL_HEADER_FLAG=""
if [ -n "${NVM_AUTH_HEADER:-}" ]; then
sanitized_header=$(nvm_sanitize_auth_header "${NVM_AUTH_HEADER}")
CURL_HEADER_FLAG="--header \"Authorization: ${sanitized_header}\""
fi
if nvm_curl_use_compression; then
CURL_COMPRESSED_FLAG="--compressed"
fi
local NVM_DOWNLOAD_ARGS
NVM_DOWNLOAD_ARGS=''
for arg in "$@"; do
NVM_DOWNLOAD_ARGS="${NVM_DOWNLOAD_ARGS} \"$arg\""
done
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} ${NVM_DOWNLOAD_ARGS}"
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(nvm_echo "$@" | command sed "
s/--progress-bar /--progress=bar /
s/--compressed //
s/--fail //
s/-L //
s/-I /--server-response /
s/-s /-q /
s/-sS /-nv /
s/-o /-O /
s/-C - /-c /
")
if [ -n "${NVM_AUTH_HEADER:-}" ]; then
sanitized_header=$(nvm_sanitize_auth_header "${NVM_AUTH_HEADER}")
ARGS="${ARGS} --header \"${sanitized_header}\""
fi
# shellcheck disable=SC2086
eval wget $ARGS
fi
}
nvm_sanitize_auth_header() {
# Remove potentially dangerous characters
nvm_echo "$1" | command sed 's/[^a-zA-Z0-9:;_. -]//g'
}
nvm_has_system_node() {
[ "$(nvm deactivate >/dev/null 2>&1 && command -v node)" != '' ]
}
nvm_has_system_iojs() {
[ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]
}
nvm_is_version_installed() {
if [ -z "${1-}" ]; then
return 1
fi
local NVM_NODE_BINARY
NVM_NODE_BINARY='node'
if [ "_$(nvm_get_os)" = '_win' ]; then
NVM_NODE_BINARY='node.exe'
fi
if [ -x "$(nvm_version_path "$1" 2>/dev/null)/bin/${NVM_NODE_BINARY}" ]; then
return 0
fi
return 1
}
nvm_print_npm_version() {
if nvm_has "npm"; then
local NPM_VERSION
NPM_VERSION="$(npm --version 2>/dev/null)"
if [ -n "${NPM_VERSION}" ]; then
command printf " (npm v${NPM_VERSION})"
fi
fi
}
nvm_install_latest_npm() {
nvm_echo 'Attempting to upgrade to the latest working version of npm...'
local NODE_VERSION
NODE_VERSION="$(nvm_strip_iojs_prefix "$(nvm_ls_current)")"
local NPM_VERSION
NPM_VERSION="$(npm --version 2>/dev/null)"
if [ "${NODE_VERSION}" = 'system' ]; then
NODE_VERSION="$(node --version)"
elif [ "${NODE_VERSION}" = 'none' ]; then
nvm_echo "Detected node version ${NODE_VERSION}, npm version v${NPM_VERSION}"
NODE_VERSION=''
fi
if [ -z "${NODE_VERSION}" ]; then
nvm_err 'Unable to obtain node version.'
return 1
fi
if [ -z "${NPM_VERSION}" ]; then
nvm_err 'Unable to obtain npm version.'
return 2
fi
local NVM_NPM_CMD
NVM_NPM_CMD='npm'
if [ "${NVM_DEBUG-}" = 1 ]; then
nvm_echo "Detected node version ${NODE_VERSION}, npm version v${NPM_VERSION}"
NVM_NPM_CMD='nvm_echo npm'
fi
local NVM_IS_0_6
NVM_IS_0_6=0
if nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 0.6.0 && nvm_version_greater 0.7.0 "${NODE_VERSION}"; then
NVM_IS_0_6=1
fi
local NVM_IS_0_9
NVM_IS_0_9=0
if nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 0.9.0 && nvm_version_greater 0.10.0 "${NODE_VERSION}"; then
NVM_IS_0_9=1
fi
if [ $NVM_IS_0_6 -eq 1 ]; then
nvm_echo '* `node` v0.6.x can only upgrade to `npm` v1.3.x'
$NVM_NPM_CMD install -g npm@1.3
elif [ $NVM_IS_0_9 -eq 0 ]; then
# node 0.9 breaks here, for some reason
if nvm_version_greater_than_or_equal_to "${NPM_VERSION}" 1.0.0 && nvm_version_greater 2.0.0 "${NPM_VERSION}"; then
nvm_echo '* `npm` v1.x needs to first jump to `npm` v1.4.28 to be able to upgrade further'
$NVM_NPM_CMD install -g npm@1.4.28
elif nvm_version_greater_than_or_equal_to "${NPM_VERSION}" 2.0.0 && nvm_version_greater 3.0.0 "${NPM_VERSION}"; then
nvm_echo '* `npm` v2.x needs to first jump to the latest v2 to be able to upgrade further'
$NVM_NPM_CMD install -g npm@2
fi
fi
if [ $NVM_IS_0_9 -eq 1 ] || [ $NVM_IS_0_6 -eq 1 ]; then
nvm_echo '* node v0.6 and v0.9 are unable to upgrade further'
elif nvm_version_greater 1.1.0 "${NODE_VERSION}"; then
nvm_echo '* `npm` v4.5.x is the last version that works on `node` versions < v1.1.0'
$NVM_NPM_CMD install -g npm@4.5
elif nvm_version_greater 4.0.0 "${NODE_VERSION}"; then
nvm_echo '* `npm` v5 and higher do not work on `node` versions below v4.0.0'
$NVM_NPM_CMD install -g npm@4
elif [ $NVM_IS_0_9 -eq 0 ] && [ $NVM_IS_0_6 -eq 0 ]; then
local NVM_IS_4_4_OR_BELOW
NVM_IS_4_4_OR_BELOW=0
if nvm_version_greater 4.5.0 "${NODE_VERSION}"; then
NVM_IS_4_4_OR_BELOW=1
fi
local NVM_IS_5_OR_ABOVE
NVM_IS_5_OR_ABOVE=0
if [ $NVM_IS_4_4_OR_BELOW -eq 0 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 5.0.0; then
NVM_IS_5_OR_ABOVE=1
fi
local NVM_IS_6_OR_ABOVE
NVM_IS_6_OR_ABOVE=0
local NVM_IS_6_2_OR_ABOVE
NVM_IS_6_2_OR_ABOVE=0
if [ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 6.0.0; then
NVM_IS_6_OR_ABOVE=1
if nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 6.2.0; then
NVM_IS_6_2_OR_ABOVE=1
fi
fi
local NVM_IS_9_OR_ABOVE
NVM_IS_9_OR_ABOVE=0
local NVM_IS_9_3_OR_ABOVE
NVM_IS_9_3_OR_ABOVE=0
if [ $NVM_IS_6_2_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 9.0.0; then
NVM_IS_9_OR_ABOVE=1
if nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 9.3.0; then
NVM_IS_9_3_OR_ABOVE=1
fi
fi
local NVM_IS_10_OR_ABOVE
NVM_IS_10_OR_ABOVE=0
if [ $NVM_IS_9_3_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 10.0.0; then
NVM_IS_10_OR_ABOVE=1
fi
local NVM_IS_12_LTS_OR_ABOVE
NVM_IS_12_LTS_OR_ABOVE=0
if [ $NVM_IS_10_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 12.13.0; then
NVM_IS_12_LTS_OR_ABOVE=1
fi
local NVM_IS_13_OR_ABOVE
NVM_IS_13_OR_ABOVE=0
if [ $NVM_IS_12_LTS_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 13.0.0; then
NVM_IS_13_OR_ABOVE=1
fi
local NVM_IS_14_LTS_OR_ABOVE
NVM_IS_14_LTS_OR_ABOVE=0
if [ $NVM_IS_13_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 14.15.0; then
NVM_IS_14_LTS_OR_ABOVE=1
fi
local NVM_IS_14_17_OR_ABOVE
NVM_IS_14_17_OR_ABOVE=0
if [ $NVM_IS_14_LTS_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 14.17.0; then
NVM_IS_14_17_OR_ABOVE=1
fi
local NVM_IS_15_OR_ABOVE
NVM_IS_15_OR_ABOVE=0
if [ $NVM_IS_14_LTS_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 15.0.0; then
NVM_IS_15_OR_ABOVE=1
fi
local NVM_IS_16_OR_ABOVE
NVM_IS_16_OR_ABOVE=0
if [ $NVM_IS_15_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 16.0.0; then
NVM_IS_16_OR_ABOVE=1
fi
local NVM_IS_16_LTS_OR_ABOVE
NVM_IS_16_LTS_OR_ABOVE=0
if [ $NVM_IS_16_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 16.13.0; then
NVM_IS_16_LTS_OR_ABOVE=1
fi
local NVM_IS_17_OR_ABOVE
NVM_IS_17_OR_ABOVE=0
if [ $NVM_IS_16_LTS_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 17.0.0; then
NVM_IS_17_OR_ABOVE=1
fi
local NVM_IS_18_OR_ABOVE
NVM_IS_18_OR_ABOVE=0
if [ $NVM_IS_17_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 18.0.0; then
NVM_IS_18_OR_ABOVE=1
fi
local NVM_IS_18_17_OR_ABOVE
NVM_IS_18_17_OR_ABOVE=0
if [ $NVM_IS_18_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 18.17.0; then
NVM_IS_18_17_OR_ABOVE=1
fi
local NVM_IS_19_OR_ABOVE
NVM_IS_19_OR_ABOVE=0
if [ $NVM_IS_18_17_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 19.0.0; then
NVM_IS_19_OR_ABOVE=1
fi
local NVM_IS_20_5_OR_ABOVE
NVM_IS_20_5_OR_ABOVE=0
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
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_than_or_equal_to "${NODE_VERSION}" 20.17.0; 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_than_or_equal_to "${NODE_VERSION}" 21.0.0; 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_than_or_equal_to "${NODE_VERSION}" 22.9.0; then
NVM_IS_22_9_OR_ABOVE=1
fi
if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || {
[ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \
}; then
nvm_echo '* `npm` `v5.3.x` is the last version that works on `node` 4.x versions below v4.4, or 5.x versions below v5.10, due to `Buffer.alloc`'
$NVM_NPM_CMD install -g npm@5.3
elif [ $NVM_IS_4_4_OR_BELOW -eq 0 ] && nvm_version_greater 4.7.0 "${NODE_VERSION}"; then
nvm_echo '* `npm` `v5.4.1` is the last version that works on `node` `v4.5` and `v4.6`'
$NVM_NPM_CMD install -g npm@5.4.1
elif [ $NVM_IS_6_OR_ABOVE -eq 0 ]; then
nvm_echo '* `npm` `v5.x` is the last version that works on `node` below `v6.0.0`'
$NVM_NPM_CMD install -g npm@5
elif \
{ [ $NVM_IS_6_OR_ABOVE -eq 1 ] && [ $NVM_IS_6_2_OR_ABOVE -eq 0 ]; } \
|| { [ $NVM_IS_9_OR_ABOVE -eq 1 ] && [ $NVM_IS_9_3_OR_ABOVE -eq 0 ]; } \
; then
nvm_echo '* `npm` `v6.9` is the last version that works on `node` `v6.0.x`, `v6.1.x`, `v9.0.x`, `v9.1.x`, or `v9.2.x`'
$NVM_NPM_CMD install -g npm@6.9
elif [ $NVM_IS_10_OR_ABOVE -eq 0 ]; then
if nvm_version_greater 4.4.4 "${NPM_VERSION}"; then
nvm_echo '* `npm` `v4.4.4` or later is required to install npm v6.14.18'
$NVM_NPM_CMD install -g npm@4
fi
nvm_echo '* `npm` `v6.x` is the last version that works on `node` below `v10.0.0`'
$NVM_NPM_CMD install -g npm@6
elif \
[ $NVM_IS_12_LTS_OR_ABOVE -eq 0 ] \
|| { [ $NVM_IS_13_OR_ABOVE -eq 1 ] && [ $NVM_IS_14_LTS_OR_ABOVE -eq 0 ]; } \
|| { [ $NVM_IS_15_OR_ABOVE -eq 1 ] && [ $NVM_IS_16_OR_ABOVE -eq 0 ]; } \
; then
nvm_echo '* `npm` `v7.x` is the last version that works on `node` `v13`, `v15`, below `v12.13`, or `v14.0` - `v14.15`'
$NVM_NPM_CMD install -g npm@7
elif \
{ [ $NVM_IS_12_LTS_OR_ABOVE -eq 1 ] && [ $NVM_IS_13_OR_ABOVE -eq 0 ]; } \
|| { [ $NVM_IS_14_LTS_OR_ABOVE -eq 1 ] && [ $NVM_IS_14_17_OR_ABOVE -eq 0 ]; } \
|| { [ $NVM_IS_16_OR_ABOVE -eq 1 ] && [ $NVM_IS_16_LTS_OR_ABOVE -eq 0 ]; } \
|| { [ $NVM_IS_17_OR_ABOVE -eq 1 ] && [ $NVM_IS_18_OR_ABOVE -eq 0 ]; } \
; then
nvm_echo '* `npm` `v8.6` is the last version that works on `node` `v12`, `v14.13` - `v14.16`, or `v16.0` - `v16.12`'
# ^8.7 breaks `npm ls` on file: deps
$NVM_NPM_CMD install -g npm@8.6
elif \
[ $NVM_IS_18_17_OR_ABOVE -eq 0 ] \
|| { [ $NVM_IS_19_OR_ABOVE -eq 1 ] && [ $NVM_IS_20_5_OR_ABOVE -eq 0 ]; } \
; 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_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
nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!'
$NVM_NPM_CMD install -g npm
fi
fi
nvm_echo "* npm upgraded to: v$(npm --version 2>/dev/null)"
}
# Make zsh glob matching behave same as bash
# This fixes the "zsh: no matches found" errors
if [ -z "${NVM_CD_FLAGS-}" ]; then
export NVM_CD_FLAGS=''
fi
if nvm_is_zsh; then
NVM_CD_FLAGS="-q"
fi
# Auto detect the NVM_DIR when not set
if [ -z "${NVM_DIR-}" ]; then
# shellcheck disable=SC2128
if [ -n "${BASH_SOURCE-}" ]; then
NVM_SCRIPT_SOURCE="${BASH_SOURCE}"
fi
# shellcheck disable=SC2086
NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" >/dev/null && \pwd)"
export NVM_DIR
else
# https://unix.stackexchange.com/a/198289
case $NVM_DIR in
*[!/]*/)
NVM_DIR="${NVM_DIR%"${NVM_DIR##*[!/]}"}"
export NVM_DIR
nvm_err "Warning: \$NVM_DIR should not have trailing slashes"
;;
esac
fi
unset NVM_SCRIPT_SOURCE 2>/dev/null
nvm_tree_contains_path() {
local tree
tree="${1-}"
local node_path
node_path="${2-}"
if [ "@${tree}@" = "@@" ] || [ "@${node_path}@" = "@@" ]; then
nvm_err "both the tree and the node path are required"
return 2
fi
local previous_pathdir
previous_pathdir="${node_path}"
local pathdir
pathdir=$(dirname "${previous_pathdir}")
while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] &&
[ "${pathdir}" != "${tree}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do
previous_pathdir="${pathdir}"
pathdir=$(dirname "${previous_pathdir}")
done
[ "${pathdir}" = "${tree}" ]
}
nvm_find_project_dir() {
local path_
path_="${PWD}"
while [ "${path_}" != "" ] && [ "${path_}" != '.' ] && [ ! -f "${path_}/package.json" ] && [ ! -d "${path_}/node_modules" ]; do
path_=${path_%/*}
done
nvm_echo "${path_}"
}
# Traverse up in directory tree to find containing folder
nvm_find_up() {
local path_
path_="${PWD}"
while [ "${path_}" != "" ] && [ "${path_}" != '.' ] && [ ! -f "${path_}/${1-}" ]; do
path_=${path_%/*}
done
nvm_echo "${path_}"
}
nvm_find_nvmrc() {
local dir
dir="$(nvm_find_up '.nvmrc')"
if [ -e "${dir}/.nvmrc" ]; then
nvm_echo "${dir}/.nvmrc"
fi
}
nvm_nvmrc_invalid_msg() {
local error_text
error_text="invalid .nvmrc!
all non-commented content (anything after # is a comment) must be either:
- a single bare nvm-recognized version-ish
- or, multiple distinct key-value pairs, each key/value separated by a single equals sign (=)
additionally, a single bare nvm-recognized version-ish must be present (after stripping comments)."
local warn_text
warn_text="non-commented content parsed:
${1}"
nvm_err "$(nvm_wrap_with_color_code 'r' "${error_text}")
$(nvm_wrap_with_color_code 'y' "${warn_text}")"
}
nvm_process_nvmrc() {
local NVMRC_PATH
NVMRC_PATH="$1"
local lines
lines=$(command sed 's/#.*//' "$NVMRC_PATH" | command sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | nvm_grep -v '^$')
if [ -z "$lines" ]; then
nvm_nvmrc_invalid_msg "${lines}"
return 1
fi
# Initialize key-value storage
local keys
keys=''
local values
values=''
local unpaired_line
unpaired_line=''
while IFS= read -r line; do
if [ -z "${line}" ]; then
continue
elif [ -z "${line%%=*}" ]; then
if [ -n "${unpaired_line}" ]; then
nvm_nvmrc_invalid_msg "${lines}"
return 1
fi
unpaired_line="${line}"
elif case "$line" in *'='*) true;; *) false;; esac; t
gitextract_ttgsrgia/ ├── .dockerignore ├── .editorconfig ├── .gitattributes ├── .github/ │ ├── FUNDING.yml │ ├── INCIDENT_RESPONSE_PLAN.md │ ├── ISSUE_TEMPLATE/ │ │ ├── config.yml │ │ └── issue_template.md │ ├── SECURITY.md │ ├── THREAT_MODEL.md │ └── workflows/ │ ├── codeql-analysis.yml │ ├── latest-npm.yml │ ├── lint.yml │ ├── nodejs-org.yml │ ├── nvm-install-test.yml │ ├── rebase.yml │ ├── release.yml │ ├── require-allow-edits.yml │ ├── shellcheck.yml │ ├── tests-fast.yml │ ├── tests-installation-iojs.yml │ ├── tests-installation-node.yml │ ├── tests-xenial.yml │ ├── tests.yml │ ├── toc.yml │ └── windows-npm.yml ├── .gitignore ├── .gitmodules ├── .mailmap ├── .npmrc ├── AGENTS.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dockerfile ├── GOVERNANCE.md ├── LICENSE.md ├── Makefile ├── PROJECT_CHARTER.md ├── README.md ├── ROADMAP.md ├── bash_completion ├── install.sh ├── nvm-exec ├── nvm.sh ├── package.json ├── rename_test.sh ├── test/ │ ├── common.sh │ ├── fast/ │ │ ├── Aliases/ │ │ │ ├── 'nvm alias' should ignore leading blank lines in the file │ │ │ ├── 'nvm alias' should not accept aliases with a hash │ │ │ ├── 'nvm alias' should not accept aliases with slashes │ │ │ ├── 'nvm unalias' should accept aliases when they shadow a built-in alias │ │ │ ├── 'nvm unalias' should not accept aliases with names equal to built-in alias │ │ │ ├── 'nvm unalias' should not accept aliases with slashes │ │ │ ├── Running 'nvm alias ˂aliasname˃ ˂target˃' again should change the target │ │ │ ├── Running 'nvm alias ˂aliasname˃' should list but one alias │ │ │ ├── Running 'nvm alias' lists implicit aliases when they do not exist │ │ │ ├── Running 'nvm alias' lists manual aliases instead of implicit aliases when present │ │ │ ├── Running 'nvm alias' should list all aliases │ │ │ ├── circular/ │ │ │ │ ├── nvm_resolve_alias │ │ │ │ ├── nvm_resolve_local_alias │ │ │ │ ├── setup │ │ │ │ └── teardown │ │ │ ├── lts/ │ │ │ │ ├── 'nvm alias' should ensure LTS alias dir exists │ │ │ │ ├── setup_dir │ │ │ │ └── teardown_dir │ │ │ ├── nvm_ensure_default_set │ │ │ ├── nvm_list_aliases calls nvm_get_colors │ │ │ ├── nvm_list_aliases works with LTS aliases │ │ │ ├── nvm_list_aliases works with no LTS aliases present │ │ │ ├── nvm_print_alias_path calls nvm_get_colors │ │ │ ├── nvm_print_formatted_alias calls nvm_get_colors │ │ │ ├── nvm_resolve_alias │ │ │ ├── nvm_resolve_local_alias │ │ │ ├── setup │ │ │ └── teardown │ │ ├── Listing paths/ │ │ │ ├── Running 'nvm which 0.0.2' should display only version 0.0.2 │ │ │ ├── Running 'nvm which foo' should return a nonzero exit code when not found │ │ │ ├── Running 'nvm which' should respect alias pointing to system │ │ │ └── teardown │ │ ├── Listing versions/ │ │ │ ├── Running 'nvm ls --no-alias' does not call into nvm_alias │ │ │ ├── Running 'nvm ls --no-alias' with a pattern errors │ │ │ ├── Running 'nvm ls 0.0.2' should display only version 0.0.2 │ │ │ ├── Running 'nvm ls 0.2' should display only 0.2.x versions │ │ │ ├── Running 'nvm ls default' should show system version when available │ │ │ ├── Running 'nvm ls foo' should return a nonzero exit code when not found │ │ │ ├── Running 'nvm ls io' should return NA │ │ │ ├── Running 'nvm ls node_' should return a nonzero exit code when not found │ │ │ ├── Running 'nvm ls stable' and 'nvm ls unstable' should return the appropriate implicit alias │ │ │ ├── Running 'nvm ls system' should include 'system' when appropriate │ │ │ ├── Running 'nvm ls' calls into nvm_alias │ │ │ ├── Running 'nvm ls' should display all installed versions │ │ │ ├── Running 'nvm ls' should filter out '.nvm' │ │ │ ├── Running 'nvm ls' should filter out 'versions' │ │ │ ├── Running 'nvm ls' should include 'system' when appropriate │ │ │ ├── Running 'nvm ls' should list versions in the 'versions' directory │ │ │ ├── Running 'nvm ls' should not show a trailing slash │ │ │ ├── Running 'nvm ls' with node-like versioning vx.x.x should only list a matched version │ │ │ ├── Running 'nvm ls' with nounset should not fail │ │ │ ├── Using a nonstandard IFS should not break │ │ │ └── teardown │ │ ├── Running 'nvm alias' should create a file in the alias directory │ │ ├── Running 'nvm current' should display current nvm environment │ │ ├── Running 'nvm deactivate' should unset the nvm environment variables │ │ ├── Running 'nvm install' with '--reinstall-packages-from' requires a valid version │ │ ├── Running 'nvm install' with an invalid version fails nicely │ │ ├── Running 'nvm unalias' should remove the alias file │ │ ├── Running 'nvm uninstall' should remove the appropriate directory │ │ ├── Running 'nvm uninstall' with an inferred version shows the inferred message │ │ ├── Running 'nvm uninstall' with an uninstalled version shows the requested version │ │ ├── Running 'nvm uninstall' with incorrect file permissions fails nicely │ │ ├── Running 'nvm unload' should unset all function and variables │ │ ├── Running 'nvm use foo' where 'foo' is circular aborts │ │ ├── Running 'nvm use iojs' uses latest io.js version │ │ ├── Running 'nvm use system' should work as expected │ │ ├── Running 'nvm use x' should create and change the 'current' symlink │ │ ├── Running 'nvm use x' should not create the 'current' symlink if $NVM_SYMLINK_CURRENT is false │ │ ├── Running 'nvm use' should drop CR char automatically │ │ ├── Running 'nvm use' should respect alias pointing to system │ │ ├── Running 'nvm use' should respect system in .nvmrc │ │ ├── Running 'nvm-exec' should display required node version │ │ ├── Set Colors/ │ │ │ ├── nvm_echo_with_colors │ │ │ ├── nvm_err_with_colors │ │ │ ├── nvm_print_default_alias calls nvm_get_colors │ │ │ └── nvm_print_versions calls nvm_get_colors │ │ ├── Sourcing nvm.sh should make the nvm command available │ │ ├── Sourcing nvm.sh should not modify parameters of caller │ │ ├── Unit tests/ │ │ │ ├── Running 'nvm install --save' works as expected' │ │ │ ├── Running 'nvm use --save' works as expected' │ │ │ ├── Running 'nvm use --save' works with a .nvmrc in the parent dir │ │ │ ├── Running 'nvm use --silent --save' doesn't output anything │ │ │ ├── mocks/ │ │ │ │ ├── LTS_names.txt │ │ │ │ ├── iojs.org-dist-index.tab │ │ │ │ ├── lts-star.txt │ │ │ │ ├── nodejs.org-dist-index.tab │ │ │ │ ├── nodejs.org-download-nightly-index.tab │ │ │ │ ├── nvm ls-remote iojs.txt │ │ │ │ ├── nvm ls-remote lts.txt │ │ │ │ ├── nvm ls-remote node.txt │ │ │ │ ├── nvm ls-remote.txt │ │ │ │ ├── nvm_ls_remote LTS argon.txt │ │ │ │ ├── nvm_ls_remote LTS nightly argon.txt │ │ │ │ ├── nvm_ls_remote LTS nightly.txt │ │ │ │ ├── nvm_ls_remote LTS.txt │ │ │ │ ├── nvm_ls_remote nightly.txt │ │ │ │ ├── nvm_ls_remote stable nightly.txt │ │ │ │ ├── nvm_ls_remote stable.txt │ │ │ │ ├── nvm_ls_remote.txt │ │ │ │ ├── nvm_ls_remote_iojs.txt │ │ │ │ ├── nvm_make_alias LTS alias calls.txt │ │ │ │ ├── nvm_print_implicit_alias remote stable nightly.txt │ │ │ │ ├── nvm_print_implicit_alias remote stable.txt │ │ │ │ └── project_dirs/ │ │ │ │ ├── nested-both/ │ │ │ │ │ ├── a/ │ │ │ │ │ │ └── b/ │ │ │ │ │ │ └── c/ │ │ │ │ │ │ └── d/ │ │ │ │ │ │ └── .gitkeep │ │ │ │ │ └── package.json │ │ │ │ ├── nested-n_m/ │ │ │ │ │ └── a/ │ │ │ │ │ └── b/ │ │ │ │ │ └── c/ │ │ │ │ │ └── d/ │ │ │ │ │ └── .gitkeep │ │ │ │ ├── nested-pkg/ │ │ │ │ │ ├── a/ │ │ │ │ │ │ └── b/ │ │ │ │ │ │ └── c/ │ │ │ │ │ │ └── d/ │ │ │ │ │ │ └── .gitkeep │ │ │ │ │ └── package.json │ │ │ │ ├── no-nesting-both/ │ │ │ │ │ └── package.json │ │ │ │ └── no-nesting-pkg/ │ │ │ │ └── package.json │ │ │ ├── nvm install --offline │ │ │ ├── nvm install -b │ │ │ ├── nvm install with nonlowercase LTS name │ │ │ ├── nvm ls-remote │ │ │ ├── nvm set_colors │ │ │ ├── nvm version-remote │ │ │ ├── nvm_add_iojs_prefix │ │ │ ├── nvm_alias │ │ │ ├── nvm_alias LTS-N │ │ │ ├── nvm_alias handles comments │ │ │ ├── nvm_alias_path │ │ │ ├── nvm_change_path │ │ │ ├── nvm_check_for_help │ │ │ ├── nvm_clang_version │ │ │ ├── nvm_command_info │ │ │ ├── nvm_compare_checksum │ │ │ ├── nvm_compute_checksum │ │ │ ├── nvm_curl_libz_support │ │ │ ├── nvm_curl_use_compression │ │ │ ├── nvm_curl_version │ │ │ ├── nvm_die_on_prefix │ │ │ ├── nvm_download │ │ │ ├── nvm_download_artifact │ │ │ ├── nvm_ensure_default_set │ │ │ ├── nvm_ensure_version_installed │ │ │ ├── nvm_ensure_version_prefix │ │ │ ├── nvm_extract_tarball │ │ │ ├── nvm_find_project_dir │ │ │ ├── nvm_find_up │ │ │ ├── nvm_format_version │ │ │ ├── nvm_get_arch │ │ │ ├── nvm_get_arch_unofficial │ │ │ ├── nvm_get_artifact_compression │ │ │ ├── nvm_get_checksum │ │ │ ├── nvm_get_checksum_alg │ │ │ ├── nvm_get_checksum_binary │ │ │ ├── nvm_get_colors │ │ │ ├── nvm_get_default_packages │ │ │ ├── nvm_get_default_packages mawk compat │ │ │ ├── nvm_get_download_slug │ │ │ ├── nvm_get_latest missing curl or wget │ │ │ ├── nvm_get_minor_version │ │ │ ├── nvm_get_mirror │ │ │ ├── nvm_has │ │ │ ├── nvm_has_colors │ │ │ ├── nvm_has_non_aliased │ │ │ ├── nvm_has_solaris_binary │ │ │ ├── nvm_has_system_iojs │ │ │ ├── nvm_has_system_node │ │ │ ├── nvm_install_binary_extract │ │ │ ├── nvm_install_binary_nosource │ │ │ ├── nvm_install_latest_npm │ │ │ ├── nvm_install_no_progress_bar │ │ │ ├── nvm_install_source SHELL override │ │ │ ├── nvm_iojs_prefix │ │ │ ├── nvm_iojs_version_has_solaris_binary │ │ │ ├── nvm_is_alias │ │ │ ├── nvm_is_iojs_version │ │ │ ├── nvm_is_merged_node_version │ │ │ ├── nvm_is_natural_num │ │ │ ├── nvm_is_valid_version │ │ │ ├── nvm_is_version_installed │ │ │ ├── nvm_ls handles hash in pattern │ │ │ ├── nvm_ls_current │ │ │ ├── nvm_ls_remote │ │ │ ├── nvm_ls_remote LTS aliases │ │ │ ├── nvm_ls_remote nightly │ │ │ ├── nvm_ls_remote_iojs │ │ │ ├── nvm_make_alias │ │ │ ├── nvm_node_prefix │ │ │ ├── nvm_node_version_has_solaris_binary │ │ │ ├── nvm_normalize_lts │ │ │ ├── nvm_num_version_groups │ │ │ ├── nvm_offline_version │ │ │ ├── nvm_print_alias_path │ │ │ ├── nvm_print_color_code │ │ │ ├── nvm_print_default_alias │ │ │ ├── nvm_print_implicit_alias errors │ │ │ ├── nvm_print_implicit_alias success │ │ │ ├── nvm_print_npm_version │ │ │ ├── nvm_process_nvmrc │ │ │ ├── nvm_remote_version │ │ │ ├── nvm_remote_versions │ │ │ ├── nvm_stdout_is_terminal │ │ │ ├── nvm_strip_iojs_prefix │ │ │ ├── nvm_strip_path │ │ │ ├── nvm_supports_xz │ │ │ ├── nvm_tree_contains_path │ │ │ ├── nvm_use_if_needed │ │ │ ├── nvm_validate_implicit_alias │ │ │ ├── nvm_version │ │ │ ├── nvm_version_dir │ │ │ ├── nvm_version_greater │ │ │ ├── nvm_version_path │ │ │ ├── nvm_wrap_with_color_code │ │ │ ├── nvm_write_nvmrc │ │ │ └── security_wget_injection │ │ ├── nvm should remove the last trailing slash in $NVM_DIR │ │ ├── setup │ │ ├── setup_dir │ │ ├── teardown │ │ └── teardown_dir │ ├── install_script/ │ │ ├── install_nvm_from_git │ │ ├── nvm_check_global_modules │ │ ├── nvm_detect_profile │ │ ├── nvm_do_install │ │ ├── nvm_download │ │ ├── nvm_install_dir │ │ ├── nvm_install_profile_skip │ │ ├── nvm_install_with_aliased_dot │ │ ├── nvm_install_with_node_version │ │ ├── nvm_profile_is_bash_or_zsh │ │ ├── nvm_reset │ │ └── nvm_source │ ├── installation_iojs/ │ │ ├── install already installed uses it │ │ ├── install from binary │ │ ├── install from source │ │ ├── install two versions and use the latest one │ │ ├── install version specified in .nvmrc from binary │ │ ├── install version specified in .nvmrc from source │ │ ├── install while reinstalling packages │ │ ├── nvm install v1 works │ │ ├── setup_dir │ │ └── teardown_dir │ ├── installation_node/ │ │ ├── default-packages │ │ ├── install LTS │ │ ├── install already installed uses it │ │ ├── install from binary │ │ ├── install from binary with binary flag set │ │ ├── install from source │ │ ├── install from source with thread parameter │ │ ├── install from source without V8 snapshot for ARM │ │ ├── install hook │ │ ├── install latest npm │ │ ├── install on bash with ERR trap and set -E │ │ ├── install two versions and use the latest one │ │ ├── install version specified in .nvmrc from binary │ │ ├── install while reinstalling packages │ │ ├── install with --alias │ │ ├── install with --default │ │ ├── install with --latest-npm │ │ ├── setup_dir │ │ └── teardown_dir │ ├── mocks/ │ │ ├── isainfo_amd64 │ │ ├── isainfo_x86 │ │ ├── pkg_info_amd64 │ │ ├── pkg_info_fail │ │ ├── pkg_info_x86 │ │ ├── uname_linux_armv8l │ │ ├── uname_osx_amd64 │ │ ├── uname_osx_x86 │ │ ├── uname_smartos_amd64 │ │ └── uname_smartos_x86 │ ├── slow/ │ │ ├── Running 'nvm current' should display current nvm environment │ │ ├── nvm exec/ │ │ │ ├── Running 'nvm exec --lts' should work │ │ │ ├── Running 'nvm exec --silent' should work │ │ │ ├── Running 'nvm exec 0.x' should work │ │ │ ├── Running 'nvm exec' should pick up .nvmrc version │ │ │ ├── Running 'nvm exec' with help should not parse │ │ │ ├── setup_dir │ │ │ └── teardown_dir │ │ ├── nvm reinstall-packages/ │ │ │ ├── Running 'nvm copy-packages $(nvm ls current)' should error out │ │ │ ├── setup_dir │ │ │ ├── should work as expected │ │ │ ├── teardown_dir │ │ │ ├── test-npmlink/ │ │ │ │ ├── index.js │ │ │ │ └── package.json │ │ │ └── works with no installs │ │ ├── nvm run/ │ │ │ ├── Running 'nvm run --harmony --version' should work │ │ │ ├── Running 'nvm run --lts' should work │ │ │ ├── Running 'nvm run --silent' should work │ │ │ ├── Running 'nvm run 0.x' should error out sensibly when 0.x is not installed │ │ │ ├── Running 'nvm run 0.x' should work │ │ │ ├── Running 'nvm run' should pick up .nvmrc version │ │ │ ├── setup_dir │ │ │ └── teardown_dir │ │ ├── nvm uninstall/ │ │ │ ├── Running 'nvm uninstall 0.12.6' uninstalls v0.12.6 │ │ │ ├── Running 'nvm uninstall' with incorrect file permissions fails nicely │ │ │ ├── setup_dir │ │ │ └── teardown_dir │ │ ├── nvm use/ │ │ │ ├── Running 'nvm use --lts' uses latest LTS version │ │ │ ├── Running 'nvm use --lts=foo' uses latest 'foo' LTS version │ │ │ ├── Running 'nvm use iojs' uses latest io.js version │ │ │ ├── Running 'nvm use lts' shows actionable error │ │ │ ├── Running 'nvm use node --silent' doesn't print anything │ │ │ ├── Running 'nvm use node' uses latest stable node version │ │ │ ├── Running 'nvm use v1.0.0' uses iojs-v1.0.0 iojs version │ │ │ ├── Running 'nvm use' calls 'nvm_die_on_prefix' │ │ │ ├── Running 'nvm use' with nvmrc containing not installed version │ │ │ ├── setup_dir │ │ │ └── teardown_dir │ │ └── nvm_get_latest/ │ │ ├── nvm_get_latest │ │ └── nvm_get_latest failed redirect │ ├── sourcing/ │ │ ├── Sourcing nvm.sh global alias bug │ │ ├── Sourcing nvm.sh should keep version if one is active │ │ ├── Sourcing nvm.sh should use the default if available and no nvm node is loaded │ │ ├── Sourcing nvm.sh with --install and .nvmrc should install it │ │ ├── Sourcing nvm.sh with --install should install the default │ │ ├── Sourcing nvm.sh with --no-use should not use anything │ │ ├── Sourcing nvm.sh with no default should return 0 │ │ ├── setup_dir │ │ └── teardown_dir │ └── xenial/ │ ├── install from source │ ├── install from source implicitly │ ├── install from source with thread parameter │ ├── install from source without V8 snapshot for ARM │ ├── install hook │ ├── install version specified in .nvmrc from source │ └── node 0.6.21 should install 0.6.21-pre └── update_test_mocks.sh
Condensed preview — 367 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,177K chars).
[
{
"path": ".dockerignore",
"chars": 155,
"preview": "HEAD\n.cache\nv*\nalias\n\n# For testing\ntest/bak\n.urchin.log\n.urchin_stdout\ntest/**/test_output\ntest/**/.nvmrc\n\nnode_modules"
},
{
"path": ".editorconfig",
"chars": 658,
"preview": "root = true\n\n[*]\ntab_width = 2\nindent_size = 2\ncharset = utf-8\nend_of_line = lf\nindent_style = space\ninsert_final_newlin"
},
{
"path": ".gitattributes",
"chars": 19,
"preview": "* text=auto eol=lf\n"
},
{
"path": ".github/FUNDING.yml",
"chars": 574,
"preview": "# These are supported funding model platforms\n\ngithub: [ljharb]\npatreon: # Replace with a single Patreon username\nopen_c"
},
{
"path": ".github/INCIDENT_RESPONSE_PLAN.md",
"chars": 3628,
"preview": "# Incident Response Process for **nvm**\n\n## Reporting a Vulnerability\n\nWe take the security of **nvm** very seriously. I"
},
{
"path": ".github/ISSUE_TEMPLATE/config.yml",
"chars": 28,
"preview": "blank_issues_enabled: false\n"
},
{
"path": ".github/ISSUE_TEMPLATE/issue_template.md",
"chars": 1184,
"preview": "---\nname: File an issue…\nabout: Create a report to help us improve\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n<!-- Thank y"
},
{
"path": ".github/SECURITY.md",
"chars": 1464,
"preview": "# Security\n\nPlease file a private vulnerability report via GitHub, email [@ljharb](https://github.com/ljharb), or see ht"
},
{
"path": ".github/THREAT_MODEL.md",
"chars": 8743,
"preview": "# `nvm` Threat Model\n\n## Introduction\n\nThreat model analysis assists organizations to proactively identify potential sec"
},
{
"path": ".github/workflows/codeql-analysis.yml",
"chars": 1549,
"preview": "name: \"Code scanning - action\"\n\non:\n push:\n pull_request:\n schedule:\n - cron: '0 17 * * 4'\n\npermissions:\n content"
},
{
"path": ".github/workflows/latest-npm.yml",
"chars": 2196,
"preview": "name: 'Tests: `nvm install-latest-npm`'\n\non: [pull_request, push]\n\npermissions:\n contents: read\n\njobs:\n matrix:\n ru"
},
{
"path": ".github/workflows/lint.yml",
"chars": 2169,
"preview": "name: 'Tests: linting'\n\non: [pull_request, push]\n\npermissions:\n contents: read\n\njobs:\n eclint:\n runs-on: ubuntu-lat"
},
{
"path": ".github/workflows/nodejs-org.yml",
"chars": 5937,
"preview": "name: 'Update nodejs.org'\n\non:\n push:\n tags:\n - 'v*'\n workflow_dispatch:\n inputs:\n version:\n de"
},
{
"path": ".github/workflows/nvm-install-test.yml",
"chars": 3437,
"preview": "name: 'Tests: nvm install with set -e'\n\non:\n pull_request:\n push:\n workflow_dispatch:\n inputs:\n ref:\n "
},
{
"path": ".github/workflows/rebase.yml",
"chars": 288,
"preview": "name: Automatic Rebase\n\non: [pull_request_target]\n\npermissions: read-all\n\njobs:\n _:\n name: \"Automatic Rebase\"\n\n r"
},
{
"path": ".github/workflows/release.yml",
"chars": 1138,
"preview": "name: 'Tests: release process'\n\non: [pull_request, push]\n\npermissions:\n contents: read\n\njobs:\n release:\n runs-on: u"
},
{
"path": ".github/workflows/require-allow-edits.yml",
"chars": 210,
"preview": "name: Require “Allow Edits”\n\non: [pull_request_target]\n\npermissions: read-all\n\njobs:\n _:\n name: \"Require “Allow Edit"
},
{
"path": ".github/workflows/shellcheck.yml",
"chars": 1392,
"preview": "name: 'Tests: shellcheck'\n\non: [pull_request, push]\n\npermissions:\n contents: read\n\njobs:\n shellcheck_matrix:\n runs-"
},
{
"path": ".github/workflows/tests-fast.yml",
"chars": 3442,
"preview": "name: 'Tests: fast'\n\non: [push, pull_request]\n\npermissions:\n contents: read\n\njobs:\n fast:\n permissions:\n conte"
},
{
"path": ".github/workflows/tests-installation-iojs.yml",
"chars": 3339,
"preview": "name: 'Tests: installation_iojs'\n\non: [push, pull_request]\n\npermissions:\n contents: read\n\njobs:\n installation_iojs_wit"
},
{
"path": ".github/workflows/tests-installation-node.yml",
"chars": 3926,
"preview": "name: 'Tests: installation_node'\n\non: [push, pull_request]\n\npermissions:\n contents: read\n\njobs:\n installation_node:\n "
},
{
"path": ".github/workflows/tests-xenial.yml",
"chars": 3488,
"preview": "name: 'Tests: xenial'\n\non: [push, pull_request]\n\npermissions:\n contents: read\n\njobs:\n xenial:\n permissions:\n c"
},
{
"path": ".github/workflows/tests.yml",
"chars": 2557,
"preview": "name: urchin tests\n\non: [push, pull_request]\n\npermissions:\n contents: read\n\njobs:\n tests:\n permissions:\n conte"
},
{
"path": ".github/workflows/toc.yml",
"chars": 1016,
"preview": "name: update readme TOC\n\non: [push]\n\npermissions:\n contents: read\n\njobs:\n _:\n permissions:\n contents: write\n "
},
{
"path": ".github/workflows/windows-npm.yml",
"chars": 7854,
"preview": "name: 'Tests on Windows: `nvm install`'\n\non: [pull_request, push]\n\npermissions:\n contents: read\n\nenv:\n NVM_INSTALL_GIT"
},
{
"path": ".gitignore",
"chars": 277,
"preview": "# gitignore\nHEAD\n.cache\nv*\nalias\n\n# For testing\ntest/bak\n.urchin.log\n.urchin_stdout\ntest/**/test_output\ntest/**/.nvmrc\n\n"
},
{
"path": ".gitmodules",
"chars": 103,
"preview": "[submodule \"test/fixtures/nvmrc\"]\n path = test/fixtures/nvmrc\n url = git@github.com:nvm-sh/nvmrc.git\n"
},
{
"path": ".mailmap",
"chars": 48,
"preview": "Michał Gołębiowski-Owczarek <m.goleb@gmail.com>\n"
},
{
"path": ".npmrc",
"chars": 19,
"preview": "package-lock=false\n"
},
{
"path": "AGENTS.md",
"chars": 16043,
"preview": "# nvm Coding Agent Instructions\n\nThis document provides guidance for AI coding agents when working with the Node Version"
},
{
"path": "CODE_OF_CONDUCT.md",
"chars": 7560,
"preview": "# Code of Conduct\n\n`nvm`, as a member project of the OpenJS Foundation, uses [Contributor Covenant v2.1](https://www.con"
},
{
"path": "CONTRIBUTING.md",
"chars": 5817,
"preview": "# Contributing\n\n:+1::tada: First off, thanks for taking the time to contribute to `nvm`! :tada::+1:\n\nWe love pull reques"
},
{
"path": "Dockerfile",
"chars": 3696,
"preview": "# Dockerized nvm development environment\n#\n# This Dockerfile is for building nvm development environment only,\n# not for"
},
{
"path": "GOVERNANCE.md",
"chars": 467,
"preview": "# `nvm` Project Governance\n\n## Maintainers\n - [@ljharb](https://github.com/ljharb)\n\nMaintainers are responsible for iss"
},
{
"path": "LICENSE.md",
"chars": 1113,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2010 Tim Caswell\n\nCopyright (c) 2014 Jordan Harband\n\nPermission is hereby granted, "
},
{
"path": "Makefile",
"chars": 5440,
"preview": "\t# Since we rely on paths relative to the makefile location, abort if make isn't being run from there.\n$(if $(findstring"
},
{
"path": "PROJECT_CHARTER.md",
"chars": 2925,
"preview": "# `nvm` Charter\n\nnvm is a version manager for Node.js, designed to be installed per-user, and invoked per-shell. nvm wor"
},
{
"path": "README.md",
"chars": 51531,
"preview": "<a href=\"https://github.com/nvm-sh/logos\">\n <picture>\n <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://"
},
{
"path": "ROADMAP.md",
"chars": 882,
"preview": "# nvm Road Map\n\nThis is a list of the primary features planned for `nvm`:\n\n- [x] Rewriting installation code paths to su"
},
{
"path": "bash_completion",
"chars": 2299,
"preview": "#!/usr/bin/env bash\n\n# bash completion for Node Version Manager (NVM)\n\nif ! command -v nvm &> /dev/null; then\n return\nf"
},
{
"path": "install.sh",
"chars": 16774,
"preview": "#!/usr/bin/env bash\n\n{ # this ensures the entire script is downloaded #\n\nnvm_has() {\n type \"$1\" > /dev/null 2>&1\n}\n\nnvm"
},
{
"path": "nvm-exec",
"chars": 465,
"preview": "#!/usr/bin/env bash\n\nDIR=\"$(command cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\n\nunset NVM_CD_FLAGS\n\n# shellcheck di"
},
{
"path": "nvm.sh",
"chars": 155837,
"preview": "# Node Version Manager\n# Implemented as a POSIX-compliant function\n# Should work on sh, dash, bash, ksh, zsh\n# To use so"
},
{
"path": "package.json",
"chars": 2925,
"preview": "{\n \"name\": \"nvm\",\n \"version\": \"0.40.4\",\n \"description\": \"Node Version Manager - Simple bash script to manage multiple"
},
{
"path": "rename_test.sh",
"chars": 1233,
"preview": "#! /usr/bin/env bash\n\nfind_name(){\n find test -name \"*[\\\\/:\\*\\?\\\"<>\\|]*\" -o -name \"*.\"\n}\n\ncheck_name() {\n if [ \"$(find"
},
{
"path": "test/common.sh",
"chars": 6055,
"preview": "# Runs a command once and captures stdout and exit code.\n# Suppresses xtrace in the subshell. Discards stderr.\n#\n# Sets:"
},
{
"path": "test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file",
"chars": 465,
"preview": "#!/bin/sh\n\ndie() { echo \"$@\" ; exit 1; }\n\nexport NVM_DIR=\"$(cd ../../.. && pwd)\"\n\n: nvm.sh\n\\. \"${NVM_DIR}/nvm.sh\"\n\\. ../"
},
{
"path": "test/fast/Aliases/'nvm alias' should not accept aliases with a hash",
"chars": 1276,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\ntry_err nvm alias foo#bar ba"
},
{
"path": "test/fast/Aliases/'nvm alias' should not accept aliases with slashes",
"chars": 1248,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\ntry_err nvm alias foo/bar ba"
},
{
"path": "test/fast/Aliases/'nvm unalias' should accept aliases when they shadow a built-in alias",
"chars": 667,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\nOUTPUT=\"$(nvm unalias node 2>&1)\"\nEXPECTED_OUTPU"
},
{
"path": "test/fast/Aliases/'nvm unalias' should not accept aliases with names equal to built-in alias",
"chars": 1287,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\nOUTPUT=\"$(nvm unalias node 2>&1)\"\nEXPECTED_OUTPU"
},
{
"path": "test/fast/Aliases/'nvm unalias' should not accept aliases with slashes",
"chars": 1242,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\ntry_err nvm unalias foo/bar\n"
},
{
"path": "test/fast/Aliases/Running 'nvm alias ˂aliasname˃ ˂target˃' again should change the target",
"chars": 877,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\nif [ -n \"$ZSH_VERSION\" ]; the"
},
{
"path": "test/fast/Aliases/Running 'nvm alias ˂aliasname˃' should list but one alias",
"chars": 84,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n[ $(nvm alias test-stable-1 | wc -l) = '2' ]\n"
},
{
"path": "test/fast/Aliases/Running 'nvm alias' lists implicit aliases when they do not exist",
"chars": 1266,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\nNVM_ALIAS_OUTPUT=$(nvm alias "
},
{
"path": "test/fast/Aliases/Running 'nvm alias' lists manual aliases instead of implicit aliases when present",
"chars": 1682,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\ncleanup () {\n rm -r"
},
{
"path": "test/fast/Aliases/Running 'nvm alias' should list all aliases",
"chars": 3106,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\nNVM_ALIAS_OUTPUT=\"$(nvm alias"
},
{
"path": "test/fast/Aliases/circular/nvm_resolve_alias",
"chars": 1633,
"preview": "#!/bin/sh\n\\. ../../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../../nvm.sh\n\nALIAS=\"$(nvm_resolve_al"
},
{
"path": "test/fast/Aliases/circular/nvm_resolve_local_alias",
"chars": 1693,
"preview": "#!/bin/sh\n\\. ../../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../../nvm.sh\n\nALIAS=\"$(nvm_resolve_lo"
},
{
"path": "test/fast/Aliases/circular/setup",
"chars": 193,
"preview": "#!/bin/sh\n\necho loopback > ../../../../alias/loopback\n\necho two > ../../../../alias/one\necho three > ../../../../alias/t"
},
{
"path": "test/fast/Aliases/circular/teardown",
"chars": 161,
"preview": "#!/bin/sh\n\nrm -f ../../../../alias/loopback\n\nrm -f ../../../../alias/one\nrm -f ../../../../alias/two\nrm -f ../../../../a"
},
{
"path": "test/fast/Aliases/lts/'nvm alias' should ensure LTS alias dir exists",
"chars": 364,
"preview": "#!/bin/sh\n\nset -ex\n\n: nvm.sh\n\\. ../../../../nvm.sh\n\\. ../../../common.sh\n\nLTS_ALIAS_PATH=\"$(nvm_alias_path)/lts\"\n\nrm -rf"
},
{
"path": "test/fast/Aliases/lts/setup_dir",
"chars": 200,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../../nvm.sh\n\nLTS_ALIAS_PATH=\"$(nvm_alias_path)/lts\"\n\nif [ -d \"${LTS_ALIAS_PATH}\" ]; then\n "
},
{
"path": "test/fast/Aliases/lts/teardown_dir",
"chars": 204,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../../nvm.sh\n\nLTS_ALIAS_PATH=\"$(nvm_alias_path)/lts\"\n\nif [ -d \"${LTS_ALIAS_PATH}.bak\" ]; th"
},
{
"path": "test/fast/Aliases/nvm_ensure_default_set",
"chars": 706,
"preview": "#!/bin/sh\n\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nnvm alias default 0.1 >/dev/"
},
{
"path": "test/fast/Aliases/nvm_list_aliases calls nvm_get_colors",
"chars": 555,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\nset -e\n\nnvm_has_colors() { return 0; }\n\nnvm_get_"
},
{
"path": "test/fast/Aliases/nvm_list_aliases works with LTS aliases",
"chars": 729,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\ndie () {\n echo \"$@\"\n exit 1\n}\n\nset -e\n\nMOCKS_DIR=\"../Unit tests/mocks\"\n\n# samp"
},
{
"path": "test/fast/Aliases/nvm_list_aliases works with no LTS aliases present",
"chars": 384,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\ndie () {\n mv \"$(nvm_alias_path)/_lts.bak\" \"$(nvm_alias_path)/lts\"\n echo \"$@\"\n "
},
{
"path": "test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors",
"chars": 688,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\ndie () {\n # echo \"$@\" ;\n echo \"Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<\""
},
{
"path": "test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors",
"chars": 690,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\ndie () {\n echo \"Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<\"\n exit 1\n}\n\nset"
},
{
"path": "test/fast/Aliases/nvm_resolve_alias",
"chars": 1663,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\nexport NVM_DIR=\"$(cd ../../.. && pwd)\"\n\n: nvm.sh\n\\. \"${NVM_DIR}/nvm.sh\"\n\nEXIT"
},
{
"path": "test/fast/Aliases/nvm_resolve_local_alias",
"chars": 1553,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nEXIT_CODE=$(nvm_resolve_local_alias ; echo $?)\n["
},
{
"path": "test/fast/Aliases/setup",
"chars": 343,
"preview": "#!/bin/sh\n\nexport NVM_DIR=\"$(cd ../../.. && pwd)\"\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nfor i in $(seq 1 10)\n"
},
{
"path": "test/fast/Aliases/teardown",
"chars": 492,
"preview": "#!/bin/sh\n\nfor i in $(seq 1 10)\n do\n rm -f \"../../../alias/test-stable-$i\"\n rm -rf \"../../../v0.0.$i\"\n rm -f \"../../"
},
{
"path": "test/fast/Listing paths/Running 'nvm which 0.0.2' should display only version 0.0.2",
"chars": 863,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.0.2\nmake_fake_node v0.0.20\nmake_fake_node v"
},
{
"path": "test/fast/Listing paths/Running 'nvm which foo' should return a nonzero exit code when not found",
"chars": 87,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nnvm which nonexistent_version\n[ \"_$?\" = \"_1\" ]\n"
},
{
"path": "test/fast/Listing paths/Running 'nvm which' should respect alias pointing to system",
"chars": 738,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\ncleanup() {\n rm -f \"$(nvm_alias_path)/default\"\n if [ -n \""
},
{
"path": "test/fast/Listing paths/teardown",
"chars": 71,
"preview": "rm -rf ../../../v0.0.2\nrm -rf ../../../v0.0.20\nrm -rf ../../../v0.12.0\n"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls --no-alias' does not call into nvm_alias",
"chars": 905,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; unset -f nvm_ls nvm_list_aliases; exit 1"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls --no-alias' with a pattern errors",
"chars": 509,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; unset -f nvm_ls nvm_list_aliases; exit 1"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls 0.0.2' should display only version 0.0.2",
"chars": 420,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.0.2\nmake_fake_node v0.0.20\n\ndie () { echo \""
},
{
"path": "test/fast/Listing versions/Running 'nvm ls 0.2' should display only 0.2.x versions",
"chars": 870,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.1.3\nmake_fake_node v0.2.3\nmake_fake_node v0"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls default' should show system version when available",
"chars": 553,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\ncleanup () {\n rm -f \"$(nvm_alias_path)/default\"\n unset -f nvm_has_"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls foo' should return a nonzero exit code when not found",
"chars": 82,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nnvm ls nonexistent_version\n[ \"$?\" = \"3\" ]\n"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls io' should return NA",
"chars": 65,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nnvm ls io\n[ \"$?\" = \"3\" ]\n"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls node_' should return a nonzero exit code when not found",
"chars": 68,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nnvm ls node_\n[ \"$?\" = \"3\" ]\n"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls stable' and 'nvm ls unstable' should return the appropriate implicit alias",
"chars": 911,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\nmake_fake_node v0.2.3\nmake_fa"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls system' should include 'system' when appropriate",
"chars": 567,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.0.1\nmake_fa"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias",
"chars": 899,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; unset -f nvm_ls nvm_list_aliases; exit 1"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls' should display all installed versions",
"chars": 1469,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\nmake_fake_node v0.0.1\nmake_fa"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls' should filter out '.nvm'",
"chars": 201,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.1.3\nmake_fake_node v0.2.3\n\n[ -z `nvm ls | g"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls' should filter out 'versions'",
"chars": 208,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.1.3\nmake_fake_node v0.2.3\n\n[ -z \"$(nvm ls |"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls' should include 'system' when appropriate",
"chars": 539,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.0.1\nmake_fa"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls' should list versions in the 'versions' directory",
"chars": 329,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.12.1\nmake_f"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls' should not show a trailing slash",
"chars": 1022,
"preview": "#!/bin/zsh\n\nexport NVM_DIR=\"$(cd ../../.. && pwd)\"\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nif type setopt >/dev"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls' with node-like versioning vx.x.x should only list a matched version",
"chars": 197,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.1.2\n\nnvm ls v0.1 | grep v0.1.2 &&\nnvm ls v0"
},
{
"path": "test/fast/Listing versions/Running 'nvm ls' with nounset should not fail",
"chars": 631,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.12.34 || di"
},
{
"path": "test/fast/Listing versions/Using a nonstandard IFS should not break",
"chars": 306,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nmake_fake_node v0.0.1\nmake_fake_node v0.0.3\nmake_fake_node v0"
},
{
"path": "test/fast/Listing versions/teardown",
"chars": 384,
"preview": "rm -rf ../../../v0.0.1\nrm -rf ../../../v0.0.2\nrm -rf ../../../v0.0.3\nrm -rf ../../../v0.0.9\nrm -rf ../../../v0.0.20\nrm -"
},
{
"path": "test/fast/Running 'nvm alias' should create a file in the alias directory",
"chars": 155,
"preview": "#!/bin/sh\n\nset -ex\n\nexport NVM_DIR=\"$(cd ../.. && pwd)\"\n\n: nvm.sh\n\\. ../../nvm.sh\n\nnvm alias test v0.1.2\n\n[ \"$(cat \"$(nv"
},
{
"path": "test/fast/Running 'nvm current' should display current nvm environment",
"chars": 275,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; exit 1; }\n\nexport NVM_DIR=\"$(cd ../.. && pwd)\"\n\n: nvm.sh\n\\. ../../nvm.sh\n\nnvm d"
},
{
"path": "test/fast/Running 'nvm deactivate' should unset the nvm environment variables",
"chars": 1019,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; exit 1; }\n\nexport NVM_DIR=\"$(cd ../.. && pwd)\"\n\n: nvm.sh\n\\. ../../nvm.sh\n\\. ../"
},
{
"path": "test/fast/Running 'nvm install' with '--reinstall-packages-from' requires a valid version",
"chars": 2557,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\ncleanup () {\n rm -rf \"${NVM_DIR}/v0.10.4\"\n}\n\nexport NVM_DI"
},
{
"path": "test/fast/Running 'nvm install' with an invalid version fails nicely",
"chars": 421,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; exit 1; }\n\nexport NVM_DIR=\"$(cd ../.. && pwd)\"\n\n: nvm.sh\n\\. ../../nvm.sh\n\nset +"
},
{
"path": "test/fast/Running 'nvm unalias' should remove the alias file",
"chars": 156,
"preview": "#!/bin/sh\n\nset -ex\n\nALIAS_PATH=\"../../alias\"\n\necho v0.1.2 > \"${ALIAS_PATH}/test\"\n\n: nvm.sh\n\\. ../../nvm.sh\n\nnvm unalias "
},
{
"path": "test/fast/Running 'nvm uninstall' should remove the appropriate directory",
"chars": 125,
"preview": "#!/bin/sh\n\nset -ex\n\n: nvm.sh\n\\. ../../nvm.sh\n\\. ../common.sh\n\nmake_fake_node v0.0.1\n\nnvm uninstall v0.0.1\n\n[ ! -d 'v0.0."
},
{
"path": "test/fast/Running 'nvm uninstall' with an inferred version shows the inferred message",
"chars": 349,
"preview": "#!/bin/sh\n\nset -ex\n\n\\. ../../nvm.sh\n\\. ../common.sh\n\nVERSION='v0.0.1'\nPATTERN='0.0'\n\nmkdir -p \"${NVM_DIR}/${VERSION}\"\n\ns"
},
{
"path": "test/fast/Running 'nvm uninstall' with an uninstalled version shows the requested version",
"chars": 238,
"preview": "#!/bin/sh\n\nset -ex\n\n\\. ../../nvm.sh\n\\. ../common.sh\n\nset +ex # needed for stderr\nRETURN_MESSAGE=\"$(nvm uninstall 22 2>&1"
},
{
"path": "test/fast/Running 'nvm uninstall' with incorrect file permissions fails nicely",
"chars": 329,
"preview": "#!/bin/sh\n\nset -ex\n\n: nvm.sh\n\\. ../../nvm.sh\n\\. ../common.sh\n\nmake_fake_node v0.0.1\nsudo touch \"\"$(nvm_version_path v0.0"
},
{
"path": "test/fast/Running 'nvm unload' should unset all function and variables",
"chars": 732,
"preview": "#!/bin/sh\n\nset -ex\n\nBEFORE=\"./before.tmp\"\nAFTER=\"./after.tmp\"\n\ncleanup () { rm -f \"${BEFORE}\" \"${AFTER}\"; }\ndie () { ech"
},
{
"path": "test/fast/Running 'nvm use foo' where 'foo' is circular aborts",
"chars": 819,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup() {\n rm -rf \"$(nvm_alias_path)/foo\"\n}\n\n: nvm.sh\n\\"
},
{
"path": "test/fast/Running 'nvm use iojs' uses latest io.js version",
"chars": 1038,
"preview": "#!/bin/sh\n\nset -ex\n\n\\. ../common.sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\nVERSION=\"v3.99.0\"\n\ncleanup() {\n unset -f"
},
{
"path": "test/fast/Running 'nvm use system' should work as expected",
"chars": 1565,
"preview": "#!/bin/sh\n\nset -eux\n\ncleanup() {\n unset -f nvm_has_system_node nvm_print_npm_version\n}\ndie() { echo \"$@\" ; cleanup ; ex"
},
{
"path": "test/fast/Running 'nvm use x' should create and change the 'current' symlink",
"chars": 779,
"preview": "#!/bin/sh\n\nset -ex\n\nexport NVM_SYMLINK_CURRENT=true\n: nvm.sh\n\\. ../../nvm.sh\n\\. ../common.sh\n\nrm -rf \"${NVM_DIR}/v0.10.2"
},
{
"path": "test/fast/Running 'nvm use x' should not create the 'current' symlink if $NVM_SYMLINK_CURRENT is false",
"chars": 2034,
"preview": "#!/bin/sh\n\nset -ex\n\n: nvm.sh\n\\. ../../nvm.sh\n\\. ../common.sh\n\nTEST_NODE_VERSION=\"v0.10.29\"\n\nTEST_COUNT=0\nTEST_PASSED=0\nT"
},
{
"path": "test/fast/Running 'nvm use' should drop CR char automatically",
"chars": 536,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup() {\n unset VERSION1 VERSION2 VERSION3\n rm .nvmrc"
},
{
"path": "test/fast/Running 'nvm use' should respect alias pointing to system",
"chars": 907,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\ncleanup () {\n rm -f \"$(nvm_alias_path)/default\"\n if [ -n "
},
{
"path": "test/fast/Running 'nvm use' should respect system in .nvmrc",
"chars": 1056,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\ncleanup () {\n rm -f .nvmrc\n if [ -f .nvmrc.orig ]; then\n "
},
{
"path": "test/fast/Running 'nvm-exec' should display required node version",
"chars": 563,
"preview": "#!/bin/bash\n\nset -x\n: nvm.sh\n\\. ../../nvm.sh\n\ncleanup() { rm -f .nvmrc; }\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\nNVM_"
},
{
"path": "test/fast/Set Colors/nvm_echo_with_colors",
"chars": 351,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () {\n echo \"Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<\"\n exit 1\n}\n\ncleanup() {\n echo \"Tes"
},
{
"path": "test/fast/Set Colors/nvm_err_with_colors",
"chars": 340,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup() {\n echo \"Tested nvm_err_with_colors\"\n}\n\n: nvm.s"
},
{
"path": "test/fast/Set Colors/nvm_print_default_alias calls nvm_get_colors",
"chars": 622,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\ndie () {\n # echo \"$@\" ;\n echo \"Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<\""
},
{
"path": "test/fast/Set Colors/nvm_print_versions calls nvm_get_colors",
"chars": 1182,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n#set -e #nvm use system returns 127 and No system set message\n\ndie () {\n # echo"
},
{
"path": "test/fast/Sourcing nvm.sh should make the nvm command available",
"chars": 50,
"preview": "#!/bin/sh\n\nset -ex\n\n: nvm.sh\n\\. ../../nvm.sh\n\nnvm\n"
},
{
"path": "test/fast/Sourcing nvm.sh should not modify parameters of caller",
"chars": 71,
"preview": "#!/bin/sh\n\nset -ex\n\nset -- yes\n: nvm.sh\n\\. ../../nvm.sh\n[ \"$1\" = yes ]\n"
},
{
"path": "test/fast/Unit tests/Running 'nvm install --save' works as expected'",
"chars": 1373,
"preview": "#!/bin/sh\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nset -e\n\nTEST_VERSION='v0.2.4'\n\nif [ -f .nvmrc ]; then mv .nvmr"
},
{
"path": "test/fast/Unit tests/Running 'nvm use --save' works as expected'",
"chars": 1365,
"preview": "#!/bin/sh\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nset -e\n\nTEST_VERSION='v0.2.4'\n\nif [ -f .nvmrc ]; then mv .nvmr"
},
{
"path": "test/fast/Unit tests/Running 'nvm use --save' works with a .nvmrc in the parent dir",
"chars": 1205,
"preview": "#!/bin/sh\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nset -e\n\nTEST_VERSION=\"v0.2.4\"\n\nif [ -f .nvmrc ]; then mv .nvmr"
},
{
"path": "test/fast/Unit tests/Running 'nvm use --silent --save' doesn't output anything",
"chars": 1247,
"preview": "#!/bin/sh\n: nvm.sh\n\\. ../../../nvm.sh\n\\. ../../common.sh\n\nset -e\n\nTEST_VERSION=\"v0.2.4\"\n\nif [ -f .nvmrc ]; then mv .nvmr"
},
{
"path": "test/fast/Unit tests/mocks/LTS_names.txt",
"chars": 68,
"preview": "jod\niron\nhydrogen\ngallium\nfermium\nerbium\ndubnium\ncarbon\nboron\nargon\n"
},
{
"path": "test/fast/Unit tests/mocks/iojs.org-dist-index.tab",
"chars": 7395,
"preview": "version\tdate\tfiles\tnpm\tv8\tuv\tzlib\topenssl\tmodules\nv3.3.1\t2015-09-15\theaders,linux-arm64,linux-armv6l,linux-armv7l,linux-"
},
{
"path": "test/fast/Unit tests/mocks/lts-star.txt",
"chars": 8,
"preview": "lts/jod\n"
},
{
"path": "test/fast/Unit tests/mocks/nodejs.org-dist-index.tab",
"chars": 179944,
"preview": "version\tdate\tfiles\tnpm\tv8\tuv\tzlib\topenssl\tmodules\tlts\tsecurity\nv23.1.0\t2024-10-24\taix-ppc64,headers,linux-arm64,linux-ar"
},
{
"path": "test/fast/Unit tests/mocks/nodejs.org-download-nightly-index.tab",
"chars": 207673,
"preview": "version\tdate\tfiles\tnpm\tv8\tuv\tzlib\topenssl\tmodules\tlts\tsecurity\nv24.0.0-nightly20241031996708042b\t2024-10-31\taix-ppc64,he"
},
{
"path": "test/fast/Unit tests/mocks/nvm ls-remote iojs.txt",
"chars": 656,
"preview": " iojs-v1.0.0\n iojs-v1.0.1\n iojs-v1.0.2\n iojs-v1.0.3\n iojs-v1.0.4\n iojs-v1.1.0\n iojs-v1.2.0\n iojs"
},
{
"path": "test/fast/Unit tests/mocks/nvm ls-remote lts.txt",
"chars": 10147,
"preview": " v4.2.0 \u001b[0;37m (LTS: Argon)\u001b[0m\n v4.2.1 \u001b[0;37m (LTS: Argon)\u001b[0m\n v4.2.2 \u001b[0;37m (LTS: Argon"
},
{
"path": "test/fast/Unit tests/mocks/nvm ls-remote node.txt",
"chars": 18547,
"preview": " v0.1.14\n v0.1.15\n v0.1.16\n v0.1.17\n v0.1.18\n v0.1.19\n v0.1.20\n "
},
{
"path": "test/fast/Unit tests/mocks/nvm ls-remote.txt",
"chars": 19203,
"preview": " v0.1.14\n v0.1.15\n v0.1.16\n v0.1.17\n v0.1.18\n v0.1.19\n v0.1.20\n "
},
{
"path": "test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt",
"chars": 470,
"preview": "v4.2.0 Argon\nv4.2.1 Argon\nv4.2.2 Argon\nv4.2.3 Argon\nv4.2.4 Argon\nv4.2.5 Argon\nv4.2.6 Argon\nv4.3.0 Argon\nv4.3.1 Argon\nv4."
},
{
"path": "test/fast/Unit tests/mocks/nvm_ls_remote LTS nightly argon.txt",
"chars": 4,
"preview": "N/A\n"
},
{
"path": "test/fast/Unit tests/mocks/nvm_ls_remote LTS nightly.txt",
"chars": 301,
"preview": "v6.9.6-nightly201702013f61aae59d Boron *\nv8.9.1-nightly20171104a815e1b6a2 Carbon *\nv10.15.3-nightly20190301156e4c8e89 Du"
},
{
"path": "test/fast/Unit tests/mocks/nvm_ls_remote LTS.txt",
"chars": 3645,
"preview": "v4.2.0 Argon\nv4.2.1 Argon\nv4.2.2 Argon\nv4.2.3 Argon\nv4.2.4 Argon\nv4.2.5 Argon\nv4.2.6 Argon\nv4.3.0 Argon\nv4.3.1 Argon\nv4."
},
{
"path": "test/fast/Unit tests/mocks/nvm_ls_remote nightly.txt",
"chars": 1849,
"preview": "v0.10.41-nightly20151203036580393d\nv0.10.42-nightly20160128b125512a5c\nv0.12.10-nightly20160128a305339f66\nv4.0.0-nightly2"
},
{
"path": "test/fast/Unit tests/mocks/nvm_ls_remote stable nightly.txt",
"chars": 34,
"preview": "v24.0.0-nightly20241031996708042b\n"
},
{
"path": "test/fast/Unit tests/mocks/nvm_ls_remote stable.txt",
"chars": 8,
"preview": "v23.1.0\n"
},
{
"path": "test/fast/Unit tests/mocks/nvm_ls_remote.txt",
"chars": 7794,
"preview": "v0.1.14\nv0.1.15\nv0.1.16\nv0.1.17\nv0.1.18\nv0.1.19\nv0.1.20\nv0.1.21\nv0.1.22\nv0.1.23\nv0.1.24\nv0.1.25\nv0.1.26\nv0.1.27\nv0.1.28\n"
},
{
"path": "test/fast/Unit tests/mocks/nvm_ls_remote_iojs.txt",
"chars": 492,
"preview": "iojs-v1.0.0\niojs-v1.0.1\niojs-v1.0.2\niojs-v1.0.3\niojs-v1.0.4\niojs-v1.1.0\niojs-v1.2.0\niojs-v1.3.0\niojs-v1.4.1\niojs-v1.4.2\n"
},
{
"path": "test/fast/Unit tests/mocks/nvm_make_alias LTS alias calls.txt",
"chars": 209,
"preview": "lts/*|lts/jod\nlts/jod|v22.11.0\nlts/iron|v20.18.0\nlts/hydrogen|v18.20.4\nlts/gallium|v16.20.2\nlts/fermium|v14.21.3\nlts/erb"
},
{
"path": "test/fast/Unit tests/mocks/nvm_print_implicit_alias remote stable nightly.txt",
"chars": 5,
"preview": "24.0\n"
},
{
"path": "test/fast/Unit tests/mocks/nvm_print_implicit_alias remote stable.txt",
"chars": 5,
"preview": "23.1\n"
},
{
"path": "test/fast/Unit tests/mocks/project_dirs/nested-both/a/b/c/d/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "test/fast/Unit tests/mocks/project_dirs/nested-both/package.json",
"chars": 0,
"preview": ""
},
{
"path": "test/fast/Unit tests/mocks/project_dirs/nested-n_m/a/b/c/d/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "test/fast/Unit tests/mocks/project_dirs/nested-pkg/a/b/c/d/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "test/fast/Unit tests/mocks/project_dirs/nested-pkg/package.json",
"chars": 0,
"preview": ""
},
{
"path": "test/fast/Unit tests/mocks/project_dirs/no-nesting-both/package.json",
"chars": 0,
"preview": ""
},
{
"path": "test/fast/Unit tests/mocks/project_dirs/no-nesting-pkg/package.json",
"chars": 0,
"preview": ""
},
{
"path": "test/fast/Unit tests/nvm install --offline",
"chars": 1484,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n\\. ../../../nvm.sh\n\n\\. ../../common.sh\n\n# Mock nvm_download to ensure no netw"
},
{
"path": "test/fast/Unit tests/nvm install -b",
"chars": 434,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nnvm_install_source() {\n exit 42\n}\n\nVERSION=\"0.7"
},
{
"path": "test/fast/Unit tests/nvm install with nonlowercase LTS name",
"chars": 869,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nREMOTE=\"${PWD}/mocks/nvm_ls_remote.txt\"\nREMOTE_I"
},
{
"path": "test/fast/Unit tests/nvm ls-remote",
"chars": 3170,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup() {\n unset -f nvm_download nvm_ls_remote nvm_ls_remote_ioj"
},
{
"path": "test/fast/Unit tests/nvm set_colors",
"chars": 1890,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup() {\n unset NVM_COLORS\n unset -f nvm_has_colors\n "
},
{
"path": "test/fast/Unit tests/nvm version-remote",
"chars": 2280,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup() {\n unset -f nvm_remote_version\n}\n\n: nvm.sh\n\\. ."
},
{
"path": "test/fast/Unit tests/nvm_add_iojs_prefix",
"chars": 417,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n[ \"_$(nvm_add_iojs_prefix 1)\" = \"_iojs-v1\" ] || "
},
{
"path": "test/fast/Unit tests/nvm_alias",
"chars": 997,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup () {\n rm -rf ../../../alias/test\n}\n\n: nvm.sh\n\\. ../../../n"
},
{
"path": "test/fast/Unit tests/nvm_alias LTS-N",
"chars": 1032,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\n\ncleanup() {\n unset -f nvm_download\n rm -rf \"${NVM_DIR}/alias/lts"
},
{
"path": "test/fast/Unit tests/nvm_alias handles comments",
"chars": 1201,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup () {\n rm -rf ../../../alias/test-comment\n rm -rf ../../.."
},
{
"path": "test/fast/Unit tests/nvm_alias_path",
"chars": 173,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n[ \"_$(nvm_alias_path)\" = \"_$NVM_DIR/alias\" ] || "
},
{
"path": "test/fast/Unit tests/nvm_change_path",
"chars": 2169,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nTEST_PATH=/usr/bin:/usr/local/bin\n\n# New version"
},
{
"path": "test/fast/Unit tests/nvm_check_for_help",
"chars": 315,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nTERM=dumb nvm clear-cache --help | grep 'Usage:'"
},
{
"path": "test/fast/Unit tests/nvm_clang_version",
"chars": 1608,
"preview": "#!/bin/sh\n\ncleanup () {\n unset -f die\n}\n\ndie () { echo -e \"$@\" ; cleanup ; exit 1; }\n\nif type \"clang\" > /dev/null 2>&1"
},
{
"path": "test/fast/Unit tests/nvm_command_info",
"chars": 1887,
"preview": "#!/bin/sh\n\ncleanup() {\n unalias wget\n unset -f wget\n unset WGET_EXPECTED_INFO WGET_COMMAND_INFO\n}\n\ndie() { echo \"$@\" "
},
{
"path": "test/fast/Unit tests/nvm_compare_checksum",
"chars": 2267,
"preview": "#!/bin/sh\n\ncleanup () {\n unset -f nvm_compute_checksum\n}\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\n: nvm.sh\n\\. ../../.."
},
{
"path": "test/fast/Unit tests/nvm_compute_checksum",
"chars": 698,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n\\. ../../common.sh\n\ntry_err nvm_compute"
},
{
"path": "test/fast/Unit tests/nvm_curl_libz_support",
"chars": 1261,
"preview": "#!/bin/sh\n\ncleanup() {\n unset -f curl\n}\n\ndie() { cleanup; echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\ncurl() {\n"
},
{
"path": "test/fast/Unit tests/nvm_curl_use_compression",
"chars": 1750,
"preview": "#!/bin/sh\n\ncleanup () {\n unset -f die\n}\n\ndie () { echo -e \"$@\" ; cleanup ; exit 1; }\n\nNVM_ENV=testing \\. ../../../nvm."
},
{
"path": "test/fast/Unit tests/nvm_curl_version",
"chars": 865,
"preview": "#!/bin/sh\n\ncleanup () {\n unset -f die\n unset -f curl\n}\n\ndie () { echo -e \"$@\" ; cleanup ; exit 1; }\n\nNVM_ENV=testing "
},
{
"path": "test/fast/Unit tests/nvm_die_on_prefix",
"chars": 9963,
"preview": "#!/bin/sh\n\nTEST_PWD=$(pwd)\nTEST_DIR=\"$TEST_PWD/nvm_die_on_prefix_tmp\"\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n\\. ../../common.sh\n\n"
},
{
"path": "test/fast/Unit tests/nvm_download",
"chars": 1285,
"preview": "#!/bin/sh\n\ncleanup () {\n unset -f die cleanup\n docker stop httpbin && docker rm httpbin\n}\ndie () { echo \"$@\" ; cleanup"
},
{
"path": "test/fast/Unit tests/nvm_download_artifact",
"chars": 2046,
"preview": "#!/bin/sh\n\ncleanup () {\n unset -f nvm_get_mirror\n}\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.s"
},
{
"path": "test/fast/Unit tests/nvm_ensure_default_set",
"chars": 532,
"preview": "#!/bin/sh\n\n\\. ../../common.sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nEXPECTED_OUTPUT=\"nvm_ensure_"
},
{
"path": "test/fast/Unit tests/nvm_ensure_version_installed",
"chars": 3283,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\ncleanup () {\n rm -rf \"$(nvm_version_path v0.1.2)\"\n unset -f nvm_ha"
},
{
"path": "test/fast/Unit tests/nvm_ensure_version_prefix",
"chars": 648,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n[ \"_$(nvm_ensure_version_prefix 1)\" = \"_v1\" ] ||"
},
{
"path": "test/fast/Unit tests/nvm_extract_tarball",
"chars": 872,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n[ \"$(nvm_extract_tarball 2>&1)\" = \"nvm_extract_t"
},
{
"path": "test/fast/Unit tests/nvm_find_project_dir",
"chars": 1496,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nset -ex\n\nTEST_DIR=\"$PWD/mocks/project_dirs\"\n\nACT"
},
{
"path": "test/fast/Unit tests/nvm_find_up",
"chars": 916,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\nsetup() {\n cleanup\n mkdir -p tmp_nvm_find_up/a/b/c/d\n touch tmp_n"
},
{
"path": "test/fast/Unit tests/nvm_format_version",
"chars": 664,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nINPUT=\"0.1.2\"\nOUTPUT=\"$(nvm_format_version \"$INP"
},
{
"path": "test/fast/Unit tests/nvm_get_arch",
"chars": 2210,
"preview": "#!/bin/sh\n\n# Save the PATH as it was when the test started to restore it when it\n# finishes\nORIG_PATH=\"${PATH}\"\n\ncleanup"
},
{
"path": "test/fast/Unit tests/nvm_get_arch_unofficial",
"chars": 2671,
"preview": "#!/bin/sh\n\n# Save the PATH as it was when the test started to restore it when it finishes\nORIG_PATH=\"${PATH}\"\n\ncleanup()"
},
{
"path": "test/fast/Unit tests/nvm_get_artifact_compression",
"chars": 670,
"preview": "#!/bin/sh\n\ncleanup () {\n unset -f die cleanup\n}\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n"
},
{
"path": "test/fast/Unit tests/nvm_get_checksum",
"chars": 1153,
"preview": "#!/bin/sh\n\nset -ex\n\ncleanup () {\n unset -f nvm_download nvm_get_checksum_alg nvm_get_mirror\n}\ndie () { echo \"$@\" ; clea"
},
{
"path": "test/fast/Unit tests/nvm_get_checksum_alg",
"chars": 281,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; exit 1; }\n\nset +e # TODO: fix\n: nvm.sh\n\\. ../../../nvm.sh\nset -e\n\nALG=\"$(nvm_ge"
},
{
"path": "test/fast/Unit tests/nvm_get_checksum_binary",
"chars": 408,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; exit 1; }\n\nset +e # TODO: fix\n: nvm.sh\n\\. ../../../nvm.sh\nset -e\n\nBIN=\"$(nvm_ge"
},
{
"path": "test/fast/Unit tests/nvm_get_colors",
"chars": 3153,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup() {\n unset NVM_COLORS\n if [ -n TEMP_NVM_COLORS ]"
},
{
"path": "test/fast/Unit tests/nvm_get_default_packages",
"chars": 2066,
"preview": "#!/bin/sh\n\n: nvm.sh\n\\. ../../../nvm.sh\n\nFILE=\"${NVM_DIR}/default-packages\"\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\nset"
},
{
"path": "test/fast/Unit tests/nvm_get_default_packages mawk compat",
"chars": 1636,
"preview": "#!/bin/sh\n\n# Test that nvm_get_default_packages awk patterns work with mawk\n# This test runs with mawk explicitly if ava"
},
{
"path": "test/fast/Unit tests/nvm_get_download_slug",
"chars": 4416,
"preview": "#!/bin/sh\n\ncleanup() {\n unset nvm_get_os\n unset nvm_get_arch\n}\n\ndie () { cleanup; echo \"$@\" ; exit 1; }\n\n: nvm.sh\n"
},
{
"path": "test/fast/Unit tests/nvm_get_latest missing curl or wget",
"chars": 455,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; cleanup ; exit 1; }\n\ncleanup() {\n unset -f nvm_has\n}\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n\\. ."
},
{
"path": "test/fast/Unit tests/nvm_get_minor_version",
"chars": 1034,
"preview": "#!/bin/sh\n\ndie () { echo \"$@\" ; exit 1; }\n\n: nvm.sh\n\\. ../../../nvm.sh\n\n\\. ../../common.sh\n\nexpect () {\n INPUT=\"$1\"\n E"
},
{
"path": "test/fast/Unit tests/nvm_get_mirror",
"chars": 2019,
"preview": "#!/bin/sh\n\nset -ex\n\ndie () { echo \"$@\" ; exit 1; }\n\nunset NVM_NODEJS_ORG_MIRROR\nunset NVM_IOJS_ORG_MIRROR\n\nset +e # TODO"
}
]
// ... and 167 more files (download for full content)
About this extraction
This page contains the full source code of the nvm-sh/nvm GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 367 files (1.0 MB), approximately 461.7k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.