Created
February 1, 2017 11:34
-
-
Save MeLlamoPablo/0abcc150c10911047fd9e5041b105c34 to your computer and use it in GitHub Desktop.
Creates a symlink to /usr/bin/node after using nvm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
sudo rm -f /usr/bin/node | |
sudo rm -f /usr/bin/npm | |
sudo ln -s $(which node) /usr/bin/ | |
sudo ln -s $(which npm) /usr/bin/ |
SystemWide:
Create a userspace independend script:
sudo tee /usr/bin/link-current-nvm-version-to-system << FILE_CONTENT
#!/bin/bash
NVM_CURRENT_BIN="\$HOME/.nvm/current/bin"
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 "\$NVM_CURRENT_BIN/node" /usr/bin/
sudo ln -s "\$NVM_CURRENT_BIN/npm" /usr/bin/
FILE_CONTENT
Create a sudoers file specific to linking: node and nvm
sudo tee /etc/sudoers.d/nvm-linking << FILE_CONTENT
%sudo ALL=(ALL:ALL) NOPASSWD: /usr/bin/rm -f /usr/bin/npm
%sudo ALL=(ALL:ALL) NOPASSWD: /usr/bin/rm -f /usr/bin/node
%sudo ALL=(ALL:ALL) NOPASSWD: /usr/bin/ln -s /home/*/npm /usr/bin/
%sudo ALL=(ALL:ALL) NOPASSWD: /usr/bin/ln -s /home/*/node /usr/bin/
FILE_CONTENT
Every User:
Add to User space: ~/.bashrc
or ~/.zshrc
export NVM_SYMLINK_CURRENT=true
export NVM_DIR="$HOME/.nvm"
export NVM_CURRENT_BIN="$NVM_DIR/current/bin"
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
source "$NVM_DIR/nvm.sh"
fi
Create an autostart file when user logs into the system (repeat for every user)
tee ~/.config/autostart/link-current-nvm-to-system.desktop << FILE_CONTENT
[Desktop Entry]
Type=Application
Terminal=false
Name=Link Current NVM to System
Exec=/usr/sbin/link-current-nvm-version-to-system
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
FILE_CONTENT
Now you can switch node/npm versions as you like and the local node/npm wil always point to the Current active version
nvm install --lts
nvm ls
Awesome <3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.