Skip to content

Instantly share code, notes, and snippets.

@BananaAcid
Last active October 4, 2018 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BananaAcid/93c319ada91c30ed904e9bc93d324a19 to your computer and use it in GitHub Desktop.
Save BananaAcid/93c319ada91c30ed904e9bc93d324a19 to your computer and use it in GitHub Desktop.
nvm nodejs and modules apt-get ubuntu for all users
# install
#
# $ curl -o- https://gist.githubusercontent.com/BananaAcid/93c319ada91c30ed904e9bc93d324a19/raw/install-nodejs-docker.sh | bash
#
# installing:
# 1. git,
# 2. nvm for all users centralized,
# 3. nodejs through nvm,
# 4. nodejs packages thorugh npm
#
# from: https://github.com/creationix/nvm/issues/1533
# Install basics
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install git-core < "/dev/null"
# install nvm for all users (centralized)
groupadd nvm && usermod -aG nvm root && \
mkdir /opt/nvm && chown :nvm /opt/nvm && chmod -R g+ws /opt/nvm && \
git clone https://github.com/creationix/nvm.git /opt/nvm && \
mkdir /opt/nvm/.cache /opt/nvm/versions /opt/nvm/alias
printf "#!/bin/bash\n\nexport NVM_DIR=\"/opt/nvm\" \n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\"\n" > /etc/profile.d/nvm.sh && \
chmod +x /etc/profile.d/nvm.sh ; \
printf "\n. /etc/profile.d/nvm.sh\n" >> /etc/bash.bashrc
# nvm availability for logged in user
printf "export NVM_DIR=\"/opt/nvm\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\"\n[ -s \"\$NVM_DIR/bash_completion\" ] && \. \"\$NVM_DIR/bash_completion\"\n" > $HOME/.profile
# install newest node using nvm + npm install required modules (docker -> will have an env change here)
. /etc/profile.d/nvm.sh && \
nvm install ` nvm ls-remote | tail -1` && \
npm i -g npm debug
printf "\n\n\nmanually run \`. /etc/profile.d/nvm.sh\` to make nvm/node/npm available in current shell\n\nremotly use: bash -lc \"node --version\"\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment