Skip to content

Instantly share code, notes, and snippets.

@MeLlamoPablo
Created February 1, 2017 11:34
Show Gist options
  • Star 91 You must be signed in to star a gist
  • Fork 22 You must be signed in to fork a gist
  • Save MeLlamoPablo/0abcc150c10911047fd9e5041b105c34 to your computer and use it in GitHub Desktop.
Save MeLlamoPablo/0abcc150c10911047fd9e5041b105c34 to your computer and use it in GitHub Desktop.
Creates a symlink to /usr/bin/node after using nvm
@NinoSkopac
Copy link

This is great

@rphlmr
Copy link

rphlmr commented May 30, 2021

Thank you so much ❤️

@Goran7777
Copy link

One more star (Y)

@MonksterFX
Copy link

Thanks for that answer! On Newer Macs it is /usr/local/bin

@NinoSkopac
Copy link

Thanks @MonksterFX

@sagivo
Copy link

sagivo commented Oct 6, 2021

👏

@jonathanvanschenck
Copy link

🚀

@alxpsr
Copy link

alxpsr commented Apr 14, 2022

Thanks

@wmentzel
Copy link

If you don't want to have to update the symlink after setting another node version via nvm, just run:

sudo ln -s node /usr/bin/

/usr/bin/node will point to node then instead of a specific version which would happen when using $(which node). Of course you should do the same for npm.

@RichardTMiles
Copy link

RichardTMiles commented May 21, 2022

A little more robust...

https://stackoverflow.com/questions/5767062/how-to-check-if-a-symlink-exists
https://linuxcommand.org/lc3_man_pages/seth.html

Thanks for the post, I googled if nvm had a flag and this was the first result :) good stuff

#!/bin/bash

set -eEB

if [ -e /usr/bin/node ]; then

  sudo rm -f /usr/bin/node

fi

if [ -e /usr/bin/npm ]; then

  sudo rm -f /usr/bin/npm

fi

sudo ln -s "$(which node)" /usr/bin/

sudo ln -s "$(which npm)" /usr/bin/

@MeLlamoPablo
Copy link
Author

If you don't want to have to update the symlink after setting another node version via nvm, just run:

sudo ln -s node /usr/bin/

/usr/bin/node will point to node then instead of a specific version which would happen when using $(which node). Of course you should do the same for npm.

Correct me if I'm wrong, but that only works for if node is already in $PATH which defeats the point of this script, which is to force node from nvm into $PATH for applications that don't support it (because most distros/apps by default will have /usr/bin in $PATH).

To be clear, I think this is a bad practice. Each user should have their own nvm installation and $NVM_DIR in $PATH.

I only originally did this because NVM was causing some frictions with WebStorm, as I couldn't make WebStorm read NVM_DIR. But nowadays WebStorm seems to support NVM natively and I personally don't have any use cases for this script.

@ClintEsteMadera
Copy link

sudo ln -s node /usr/bin/

this is the best option, IMHO. Modify once and forget forever

@rjmacarthy
Copy link

Nice one!

@fandredev
Copy link

thanks for this

@ramphy
Copy link

ramphy commented Sep 14, 2023

thank youu!

@geuis
Copy link

geuis commented Nov 4, 2023

The latest one linked sudo ln -s node /usr/bin can lead to recursive symlinks. However, using the original 4 liner at the beginning of the gist works reliably.

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