S
S
Svyatoslav Khusamov2016-08-14 06:38:20
Node.js
Svyatoslav Khusamov, 2016-08-14 06:38:20

How to install NVM for all users?

How to install NVM ( https://github.com/creationix/nvm) for all users?
Now it is installed only in the root folder (/root/.nvm).
If you try to install it from under any user, then there will be an error due to an attempt to install it in /root/.nvm, which, of course, is not available to the user.
Questions:
1) How to install NVM for a specific user?
2) How to install NVM for root so that node is accessible to all users?
The latter is more desirable, of course, so as not to produce nvm and a node for all users.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Svyatoslav Khusamov, 2016-08-14
@khusamov

Installing Node.js and NVM for all users
======================================== =====
1. First you need to install NVM for the root user.

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | NVM_DIR=/usr/local/nvm bash
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | NVM_DIR=/usr/local/nvm bash

2. Set the path to NVM for a specific user:
export NVM_DIR="/usr/local/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

In this case, node and npm will be available to the user (if accessed through the Putty terminal). But, unfortunately, these commands are not available for shipit. I don't know yet how to solve this problem.

D
dev-sasha, 2021-02-12
@dev-sasha

Installing Node.js and NVM for all users
1. Install NVM for the root user.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash

Since NVM versions are constantly released, we look at the current path to the script here:
https://nodejs.org/en/download/package-manager/#nvm

look for "install script"
2. Install node
nvm install node
3. Give users access to view /root/.nvm
chmod 755 /root
chmod 755 /root/.nvm
4. Go under the right user, for example www-data
su www-data
5. Edit .bashrc (I also add the path to node_modules in the 1st line)
vim ~/.bashrc
export PATH=./node_modules/.bin:$PATH 
export NVM_DIR="/root/.nvm"  
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm  
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

6. We exit from under the current user so that our modified bash config file is re-read.
exit
7. If we are in a docker container, we can even exit the container and restart it.
8. We go under our user, make sure that the node is located:
which node
If it does not find it, check if there is read access:
ls -la /root/.nvm

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question