Skip to content

Instantly share code, notes, and snippets.

@maxsbelt
Last active August 20, 2023 06:25
Show Gist options
  • Save maxsbelt/a401dd0c3da8b0e1d50c9eebd2eccf65 to your computer and use it in GitHub Desktop.
Save maxsbelt/a401dd0c3da8b0e1d50c9eebd2eccf65 to your computer and use it in GitHub Desktop.
node installation instruction (nodenv)

ndenv uninstallation (if necessary)

If you already have ndenv on your computer you need to remove it (it's not supported anymore). Remove commands related to ndenv from ~/.bash_profile file:

# remove those lines
export PATH="$HOME/.ndenv/bin:$PATH"
eval "$(ndenv init -)"

Remove ndenv:

$ rm -rf ~/.ndenv

nodenv installation

Install nodenv and add initializer in .bash_profile:

brew install nodenv
eval "$(nodenv init -)" # add it to .bash_profile

how to get latest stable node versions

By default nodenv uses node-build package to get information about available nodejs versions. This package can have outdated information. To get latest available node version you need to install node-build-update-defs plugin and run update-version-defs command:

git clone https://github.com/nodenv/node-build-update-defs.git "$(nodenv root)"/plugins/node-build-update-defs
nodenv update-version-defs

aliases

nodenv uses .node-version file to understand which version of nodejs should be used. By default you need to specify full version number here (e.g. 10.13.0). It's not very convenient (e.g if you decide to update dependency to next minor version (e.g. 10.13.1) you will need to update this version in .node-version file and your teammate will have to do the same thing). To prevent such problem you can use nodenv-aliases plugin. With this plugin you can specify major version in .node-version file and this symlink will point to different minor versions for different teammates. Clone this plugin:

git clone https://github.com/nodenv/nodenv-aliases.git $(nodenv root)/plugins/nodenv-aliases

node installation

Install latest node.js version (e.g. 20.5.1) and create alias for it:

nodenv install 20.5.1
nodenv global 20.5.1
nodenv alias 20 --auto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment