Skip to content

Instantly share code, notes, and snippets.

@gavinengel
Last active April 30, 2016 22:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavinengel/1842179837823dc25730 to your computer and use it in GitHub Desktop.
Save gavinengel/1842179837823dc25730 to your computer and use it in GitHub Desktop.
sudoless-npm.sh
#!/bin/sh
# Place npm packages in your home folder without using sudo
# The lazy approach to installing cli npm programs requires sudo (root) access:
# $ sudo npm install -g somenpmpackage
# Of course, I do not recommend installing npm packages with sudo unless it's required.
# This is how I install CLI tools from npm without sudo:
# $ lib
# $ npm install --save somenpmpackage
# add to end of ~/.bash_profile or ~/.zshrc so your can use: `$ lib`
if [[ ! $PATH =~ .*/bin/node/lib/node_modules/.bin* ]]; then export PATH="$HOME/bin/node/lib/node_modules/.bin:$PATH";fi;
alias lib="cd $HOME/bin/node/lib/; ll;"
# initial setup (do this stuff once)
mkdir -p ~/bin/node/lib/;
cd ~/bin/node/lib/;
npm init -y; # if npm not found, try: /usr/bin/npm init -y; /usr/bin/npm i npm;
# exceptions that need to be installed with sudo: phantom?
# TODO incorporate $(which npm) as if/then alias for new installs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment