RESOURCES
- TOPRESOURCESHEADONE
- EntryOne
- EntryTwo
- EntryThree
-
- TOPRESOURCESHEADTWO
- SubListEntryOne
- SubListEntryTwo
- SubListEntryThree
- SubListEntryFour
nvm-install without homebrew
Check out the Mac Trouble Shooting Section –
https://clickety-clack.click/img/curl-vs-wget.html
The main differences are:
wget
's major strong side compared tocurl
is its ability to download recursively.wget
is command line only. There's no lib or anything, butcurl
's features are powered by libcurl.curl
supportsFTP
,FTPS
,HTTP
,HTTPS
,SCP
,SFTP
,TFTP
,TELNET
,DICT
,LDAP
,LDAPS
,FILE
,POP3
,IMAP
,SMTP
,RTMP
andRTSP
.wget
supportsHTTP
,HTTPS
andFTP
.curl
builds and runs on more platforms thanwget
.wget
is released under a free software copyleft license (the GNU GPL).curl
is released under a free software permissive license (a MIT derivate).curl
offers upload and sending capabilities.wget
only offers plain HTTP POST support.
You can see more details at the following link:
curl vs Wget
The main differences as I (Daniel Stenberg) see them. Please consider my bias towards curl since after all, curl is my baby – but I contribute to Wget as well.
Please let me know if you have other thoughts or comments on this document.
File issues or pull-requests if you find problems or have improvements.
What both commands do
- both are command line tools that can download contents from FTP, HTTP(S)
- both can send HTTP POST requests
- both support HTTP cookies
- both support metalink, HSTS and HTTP proxy
- both are designed to work without user interaction
- both are fully open source and free software
- both projects started in 1996 (under other names)
- both are portable and run on many operating systems
How they differ
curl
- library: curl is powered by libcurl – a cross-platform library with a stable API that can be used by each and everyone. This difference is major since it creates a completely different attitude on how to do things internally. It is also slightly harder to make a library than a "mere" command line tool.
- pipes. curl works more like the traditional Unix cat command, it sends more stuff to stdout, and reads more from stdin in a "everything is a pipe" manner. Wget is more like cp, using the same analogue.
- Single shot: curl is basically made to do single-shot transfers of data. It transfers just the URLs that the user specifies, and does not contain any recursive downloading logic nor any sort of HTML parser.
- More protocols: curl supports FTP(S), GOPHER(S), HTTP(S), SCP, SFTP, TFTP, TELNET, DICT, LDAP(S), MQTT, FILE, POP3(S), IMAP(S), SMB(S), SMTP(S), RTMP and RTSP. Wget supports HTTP(S) and FTP.
- More portable: curl builds and runs on lots of more platforms than wget. For example: OS/400, TPF and other more "exotic" platforms that aren't straight-forward Unix clones. curl requires but a C89 compiler.
- More SSL libraries and SSL support: curl can be built with one out of thirteen (13!) different SSL/TLS libraries, and it offers more control and wider support for protocol details.
- HTTP auth: curl supports more HTTP authentication methods, especially over HTTP proxies: Basic, Digest, NTLM and Negotiate
- SOCKS: curl supports SOCKS4 and SOCKS5 for proxy access. With local or proxy based name resolving.
- Bidirectional: curl offers upload and sending capabilities. Wget only offers plain HTTP POST support.
- HTTP multipart/form-data sending, which allows users to do HTTP "upload" and in general emulate browsers and do HTTP automation to a wider extent.
- curl supports gzip, brotli, zstd and deflate Content-Encoding and does automatic decompression.
- curl offers and performs decompression of Transfer-Encoded HTTP, wget doesn't.
- curl supports HTTP/2, HTTP/3, alt-svc and it does dual-stack connects using Happy Eyeballs.
- curl can do many transfers in parallel (
-Z
). - Much more developer activity. While this can be debated, I consider three metrics here: mailing list activity, source code commit frequency and release frequency. Anyone following these two projects can see that the curl project has a lot higher pace in all these areas, and it has been so for 15+ years. Compare on openhub.
- curl comes pre-installed on macOS and Windows 10. Wget does not.
Wget
- Wget is command line only. There's no library.
- Recursive!: Wget's major strong side compared to curl is its ability to download recursively, or even just download everything that is referred to from a remote resource, be it a HTML page or a FTP directory listing.
- Older: Wget has traces back to its predecessor from January 9, 1996, while curl can be tracked back no earlier than to November 11, 1996.
- GPL: Wget is GPL v3. curl is MIT licensed.
- GNU: Wget is part of the GNU project and all copyrights are assigned to FSF. The curl project is entirely stand-alone and independent with no organization parenting at all with almost all copyrights owned by Daniel.
- Wget requires no extra options to simply download a remote URL to a local file, while curl requires -o or -O.
- Wget supports only GnuTLS or OpenSSL for SSL/TLS support.
- Wget supports only Basic auth as the only auth type over HTTP proxy.
- Wget has no SOCKS support.
- Its ability to recover from a prematurely broken transfer and continue downloading has no counterpart in curl.
- Wget enables more features by default: cookies, redirect-following, time stamping from the remote resource etc. With curl most of those features need to be explicitly enabled.
- There's a 'wget' in BusyBox, there's no curl there (it is not the actual wget, just a stripped down clone with the same name).
- Wget can be typed in using only the left hand on a qwerty keyboard!
- Wget requires a C99 compiler and also relies on gnulib.
When to use which
Primarily: use the one that gets the job done for you.
Wget has (recursive) downloading powers that curl does not feature and it also handle download retries over unreliable connections possibly slightly more effective.
For just about everything else, curl is probably the more suitable tool.
Additional Stuff
In recent years, wget2 is worked on to become the replacement for wget. This comparison will eventually get wget2 details as well.
Two other capable tools with similar feature set include aria2 and axel – try them out!
For a stricter feature by feature comparison (that also compares other similar tools), see the curl comparison table
Usage
To download, compile, and install the latest release of node, do this:
nvm install node # "node" is an alias for the latest version
To install a specific version of node:
nvm install 6.14.4 # or 10.10.0, 8.9.1, etc
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
:
nvm ls-remote
And then in any new shell just use the installed version:
nvm use node
Or you can just run it:
nvm run node --version
Or, you can run any arbitrary command in a subshell with the desired version of node:
nvm exec 4.2 node --version
You can also get the path to the executable to where it was installed:
nvm which 5.0
In place of a version pointer like "0.10" or "5.0" or "4.2.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 ofiojs
: this installs the latest version ofstable
: this alias is deprecated, and only truly applies tonode
v0.12
and earlier. Currently, this is an alias fornode
.unstable
: this alias points tonode
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 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
nvm install 'lts/*' --reinstall-packages-from=current
Migrating Global Packages While Installing
If you want to install a new version of Node.js and migrate npm packages from a previous version:
nvm install node --reinstall-packages-from=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:
nvm install 6 --reinstall-packages-from=5
nvm install v4.2 --reinstall-packages-from=iojs
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:
nvm install 'lts/*' --reinstall-packages-from=default --latest-npm
or, you can at any time run the following command to get the latest supported npm version on the current node version:
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.
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.
# $NVM_DIR/default-packages
rimraf
object-inspect@1.0.2
stevemao/left-pad
io.js
If you want to install io.js:
nvm install iojs
If you want to install a new version of io.js and migrate npm packages from a previous version:
nvm install iojs --reinstall-packages-from=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":
nvm use system
nvm run system --version
Listing Versions
If you want to see what versions are installed:
nvm ls
If you want to see what versions are available to install:
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
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:
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
):
nvm ls --no-colors
nvm help --no-colors
TERM=dumb nvm ls
Restoring PATH
To restore your PATH, you can deactivate it:
nvm deactivate
Set default node version
To set a default Node version to be used in any new shell, use the alias 'default':
nvm alias default node
Use a mirror of node binaries
To use a mirror of the node binaries, set $NVM_NODEJS_ORG_MIRROR
:
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
:
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.
.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:
$ 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:
$ nvm use
Found '/path/to/project/.nvmrc' with version <5.9>
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 be the <version>
(as described by nvm --help
) followed by a newline. No trailing spaces are allowed, and the trailing newline is required.
Deeper Shell Integration
You can use to deeply integrate into your shell and automatically invoke nvm
when changing directories. avn
is not supported by the nvm
development team. Please report issues to the avn
team.
If you prefer a lighter-weight solution, the recipes below have been contributed by nvm
users. They are not supported by the nvm
development team. We are, however, accepting pull requests for more examples.
bash
Automatically call nvm use
Put the following at the end of your $HOME/.bashrc
:
cdnvm() {
cd "$@";
nvm_path=$(nvm_find_up .nvmrc | 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" | tail -1 | tr -d '\->*' | 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'
cd $PWD
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
Calling nvm use
automatically in a directory with a .nvmrc
file
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
:
# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
fish
Calling nvm use
automatically in a directory with a .nvmrc
file
This requires that you have bass installed.
# ~/.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
License
nvm is released under the MIT license.
Copyright (C) 2010 Tim Caswell and 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.
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
:
[[ -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 Tab
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 Tab
default iojs lts/* lts/argon lts/boron lts/carbon lts/dubnium lts/erbium node stable unstable
$ nvm alias my_alias Tab
v10.22.0 v12.18.3 v14.8.0
nvm use:
$ nvm use Tab
my_alias default v10.22.0 v12.18.3 v14.8.0
nvm uninstall:
$ nvm uninstall Tab
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) The following are known to cause issues:
Inside ~/.npmrc
:
prefix='some/path'
Environment Variables:
$NPM_CONFIG_PREFIX
$PREFIX
Shell settings:
set -e
Installing nvm on Alpine Linux
In order to provide the best performance (and other optimisations), 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, a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions – musl. 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:
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.38.0/install.sh | bash
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.
Uninstalling / Removal
Manual Uninstall
To remove nvm
manually, execute the following:
$ rm -rf "$NVM_DIR"
Edit ~/.bashrc
(or other shell resource config) and remove the lines below:
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 14.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:
$ 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
:
$ 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:
$ 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:
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 -
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:
nvm install -s 0.8.6
- If setting the
default
alias does not establish the node version in new shells (i.e.nvm current
yieldssystem
), ensure that the system's nodePATH
is set before thenvm.sh
source line in your shell profile (see #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:
sudo chmod ugo-x /usr/libexec/path_helper
More on this issue in dotphiles/dotzsh.
nvm is not compatible with the npm config "prefix" option
Some solutions for this issue can be found here
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).
To change the user directory and/or account name follow the instructions here
Homebrew makes zsh directories unsecure
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 for some solutions related to the issue.
Macs with M1 chip
January 2021: there are no pre-compiled NodeJS binaries for versions prior to 15.x for Apple's new M1 chip (arm64 architecture).
Some issues you may encounter:
-
using
nvm
to install, say,
v14.15.4
:
-
the C code compiles successfully
-
but crashes with an out of memory error when used
-
increasing the memory available to node still produces the out of memory errors:
$ NODE_OPTIONS="--max-old-space-size=4096" ./node_modules/.bin/your_node_package
-
-
when using
nvm
to install some versions, the compilation fails
One solution to this issue is to change the architecture of your shell from arm64 to x86.
Let's assume that:
- you already have versions
12.20.1
and14.15.4
installed usingnvm
- the current version in use is
14.15.4
- you are using the
zsh
shell - you have Rosetta 2 installed (macOS prompts you to install Rosetta 2 the first time you open a Intel-only non-command-line application, or you may install Rosetta 2 from the command line with
softwareupdate --install-rosetta
)
# Check what version you're running:
$ node --version
v14.15.4
# Check architecture of the `node` binary:
$ node -p process.arch
arm64
# This confirms that the arch is for the M1 chip, which is causing the problems.
# So we need to uninstall it.
# We can't uninstall the version we are currently using, so switch to another version:
$ nvm install v12.20.1
# Now uninstall the version we want to replace:
$ nvm uninstall v14.15.4
# Launch a new zsh process under the 64-bit X86 architecture:
$ arch -x86_64 zsh
# Install node using nvm. This should download the precompiled x64 binary:
$ nvm install v14.15.4
# Now check that the architecture is correct:
$ node -p process.arch
x64
# It is now safe to return to the arm64 zsh process:
$ exit
# We're back to a native shell:
$ arch
arm64
# And the new version is now available to use:
$ nvm use v14.15.4
Now using node v14.15.4 (npm v6.14.10)
https://heynode.com/tutorial/install-nodejs-locally-nvm
NVM USAGE DOC
Install Node.js Locally with Node Version Manager (nvm)
Using nvm
(Node.js Version Manager) makes it easier to install and manage multiple versions of Node.js on a single local environment. Even if you only need a single version of Node.js right now, we still recommend using nvm because it allows you to switch between different versions of Node (depending on the requirements of your project) with minimal hassle.
In this tutorial, we'll walk through:
- How to download and install the Node Node Version Manager (nvm) shell script
- Using
nvm
to install the latest LTS version of Node.js - Switching to a different Node.js version with
nvm
By the end of this tutorial, you should be able to install the nvm
command and use it to manage different versions of Node.js on a single environment.
Goal
Install and manage a local installation of node
using nvm
.
Prerequisites
Watch
Install nvm
NVM stands for Node.js Version Manager. The nvm
command is a POSIX-compliant bash script that makes it easier to manage multiple Node.js versions on a single environment. To use it, you need to first install the bash script, and add it to your shell's $PATH
.
Learn more about why we recommend using NVM in Overview: Manage Node.js Locally.
Note: We do not recommend using nvm to install Node.js for production environments. If you're installing Node.js on your production environment you should consider using your OS's package manager, or your server tooling of choice, to install and lock the environment to a specific version of Node.js.
The official documentation for how to install nvm, and some common trouble shooting tips, is in the project's README.
Windows users: The process for installing nvm on Windows is different than what's shown below. If you're using Windows check out this Windows-specific version of nvm.
The basic process is as follows:
Download the install script
Using curl, or wget, download the installation script. In the URL below make sure you replace v0.35.0
with the latest version of nvm.
curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh -o install_nvm.sh
It's not a bad idea to open the install script and inspect its contents given that you just downloaded it from the Internet.
Run the install script
Run the install script with bash
.
bash install_nvm.sh
This script clones the nvm repository into ~/.nvm. Then it updates your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) to source the nvm.sh it contains.
You can confirm that your profile is updated by looking at the install script's output to determine which file it used. Look for something like the following in that file:
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
Restart your terminal
In order to pick up the changes to your profile either close and reopen the terminal, or manually source your respective ~/.profile.
Example:
source ~/.bash_profile
Verify it worked
Finally, you can verify that it's installed with the command
command:
command -v nvm
Should return nvm
. Note: You can't use the which
command with nvm
since it's a shell function and not an actual application.
See what it does
Finally, run the nvm
command to get a list of all the available sub-commands and to further verify that installation worked.
Use nvm to install the latest LTS release of Node.js
Now that you've got nvm installed let's use it to install, and use, the current LTS version of Node.js.
nvm install --lts
# Output
Installing latest LTS version.
Downloading and installing node v10.16.3...
Downloading https://nodejs.org/dist/v10.16.3/node-v10.16.3-darwin-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.16.3 (npm v6.9.0)
Creating default alias: default -> lts/* (-> v10.16.3)
Verify it worked, and that the version is correct:
node --version
# => v10.16.3
which node
# => /Users/joe/.nvm/versions/node/v10.16.3/bin/node
Note this line Creating default alias: default -> lts/* (-> v10.16.3)
. This indicates that nvm has set lts/*
as the default alias. Practically this means that anytime you start a new shell, and the nvm.sh script is sourced, it will default that shell to using the installed lts release. You can change this behavior using the nvm alias
command.
Example to set the default version of node to use when starting a new shell to 10.0.0:
nvm alias default 10.0.0
Use nvm to install other versions of Node.js
The real benefit of nvm comes when you install different versions of Node.js. You can then switch between them depending on which project you're working on.
List available versions
To see the entire list of Node.js versions available to install, enter the following:
nvm ls-remote
Install a specific version
Install a specific version:
nvm install 8.16.2
Install the latest release:
nvm install node
Install an older LTS release by codename:
nvm install carbon
# => Installs v8.16.2 the latest release of the Carbon LTS line.
List installed versions
You can see which versions of Node.js you have installed already, and therefore which ones you can use with the nvm ls
command:
nvm ls
This will output a list of installed versions, as well as indicate which version is currently being used by the active shell.
Switch to another version
To switch to another version for the active shell use nvm use
.
For a specific version provide a version number:
nvm use 10.16.3
# => Now using node v10.16.3 (npm v6.9.0)
Switch to the latest installed version:
nvm use node
Use the latest LTS version:
nvm use --lts
Tip: Use nvm alias default {VERSION}
to switch the version of Node.js used by default when starting a new shell.
Recap
In this tutorial we walked through installing the nvm
bash script and making sure it works. Then we used nvm
to install the latest LTS release of Node.js and set it as our environment's default Node.js version. Then we looked at how you can use nvm
to install any number of Node.js versions and switch between them as needed.
You should now be all set to execute and work on your your Node.js project(s) no matter which version of Node.js they are written for.
Further your understanding
- Run the
nvm
command with no arguments and read through the list of sub-commands that we didn't cover in this tutorial. What did you find? What might they be useful for? - Can you figure out how to switch to the version of Node.js that your OS came with?
- Why would you want to change to a different version of Node.js while doing development?
- What happens when you install an npm package globally (e.g.
npm install -g express
) while using NVM to manage Node.js versions?
Additional resources
- Official NVM repository and documentation (GitHub.com)