Skip to content

Instantly share code, notes, and snippets.

@mrbar42
Last active May 8, 2024 03:20
Show Gist options
  • Save mrbar42/faa10a68e32a40c2363aed5e150d68da to your computer and use it in GitHub Desktop.
Save mrbar42/faa10a68e32a40c2363aed5e150d68da to your computer and use it in GitHub Desktop.
Install nodenv on Ubuntu

Installing nodenv on ubuntu

nodenv is a great tool, but its installation on Ubuntu is never smooth for me. Here are instructions to install nodenv along with node-build and node-aliases plugins.

ℹ️ note - nodenv recommands updating the PATH though not all programs run in a shell. i prefer adding symlinks to the nodenv binary and shims to make it available everywhere.

The script can be pasted into a terminal as is

# install the base app
git clone https://github.com/nodenv/nodenv.git ~/.nodenv

# add nodenv to system wide bin dir to allow executing it everywhere
sudo ln -vs ~/.nodenv/bin/nodenv /usr/local/bin/nodenv

# compile dynamic bash extension to speed up nodenv - this can safely fail
cd ~/.nodenv
src/configure && make -C src || true
cd ~/

# install plugins
mkdir -p "$(nodenv root)"/plugins
git clone https://github.com/nodenv/node-build.git "$(nodenv root)"/plugins/node-build
git clone https://github.com/nodenv/nodenv-aliases.git $(nodenv root)/plugins/nodenv-aliases

# install a node version to bootstrap shims
nodenv install 14.7.0
nodenv global 14

# make shims available system wide
sudo ln -vs $(nodenv root)/shims/* /usr/local/bin/

# make sure everything is working
node --version
npm --version
npx --version
@zuernBernhard
Copy link

Works out of the box - thank you !

@Guoxweii
Copy link

good job!

@hash-dev
Copy link

hash-dev commented Apr 25, 2024

Thanks for the guide.

I was trying to setup nodenv on multiple users. I've added nodenv to my main user and added the symlink to /usr/local/bin/nodenv. I can call nodenv from other users, but apparently the plugins aren't visible to nodenv from the other users. I have to add the plugins to $HOME/.nodenv/plugins on all other accounts.

Is there a better alternative to that? Do I need to install it elsewhere?

I've decided to install nodenv on each user seperately and add it to the path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment