Skip to content

Instantly share code, notes, and snippets.

@blahah
Last active November 5, 2016 17:02
Show Gist options
  • Save blahah/cce8ac7234489a8decf44d860ea3cf05 to your computer and use it in GitHub Desktop.
Save blahah/cce8ac7234489a8decf44d860ea3cf05 to your computer and use it in GitHub Desktop.
install dat on a digitalocean droplet (fixing npm permissions issues)
# if you try to install dat on a digitalocean droplet you usually get an error like:
# sh: 1: prebuild: Permission denied
#
# this is caused by several intersecting facts:
# - digitalocean droplets, by default, only expose a root user for login
# - most node setup methods will create a node install that isn't owned by root
# - npm uses an 'undefined' user for installation
#
# and is solved in the following way:
# - taking root ownership of the node install and library install directory tree (with `chown`)
# - making npm use the calling user for installation (the `--unsafe-perm` config option)
# - remove anything installed with the wrong permissions prior to applying the previous two fixes (with `npm cache clean`)
# dependencies
sudo apt-get install build-essential libtool
# install nvm
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
# load nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# install node
nvm install --lts
# fix permissions on npm dirs
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
# make sure current user propagates to npm install
npm config set unsafe-perm true
# in case you already did the previous steps and messed up the permissions more
npm cache clean
# install dat
npm install --global dat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment