Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documenting how to install NVM for all users #1533

Open
AndreSteenveld opened this issue May 22, 2017 · 18 comments
Open

Documenting how to install NVM for all users #1533

AndreSteenveld opened this issue May 22, 2017 · 18 comments
Labels
root / multiuser issues Anything related to using `sudo` or `su`, or using nvm across multiple user accounts.

Comments

@AndreSteenveld
Copy link

I needed a global install of NVM because I have some node based cron jobs and a few legacy applications that are rather picky about which version of node they are able to work on. For a time I worked around this by sourcing the nvm script everywhere but that seems to be a somewhat unmaintainable solution.

The requirements I have:

  • NVM should just work in non-interactive sessions
  • Every user should be able to select a installed version of node (or use $ nvm exec)
  • Some users should be able to install newer versions of node

This is the solution I came up with: (shout out to @icecoldPHP, for the initial version)

  1. I've done this on a debian 8 machine, as the root user
  2. Create a group called "nvm", # groupadd nvm
  3. Add root to the nvm group # usermod -aG nvm root
  4. Goto the /opt directory and create a directory called nvm
    • Make sure the groupd owner is nvm # chown :nvm ./nvm
    • Set the permissions so that the group is allowed to write in there and all file will inherit the group # chmod g+ws ./nvm
  5. Follow the git install steps using /opt/nvm as the directory
    • To make sure the group can also write aliases, cache downloads and install global packages make sure the directories exist and have the correct permissions:
    # mkdir /opt/nvm/.cache
    # mkdir /opt/nvm/versions
    # mkdir /opt/nvm/alias 
    
    # chmod -R g+ws /opt/nvm/.cache
    # chmod -R g+ws /opt/nvm/versions
    # chmod -R g+ws /opt/nvm/alias
    
  6. Using the following snippet create /etc/profile.d/nvm.sh:
    #!/bin/bash
    
    export NVM_DIR="/opt/nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
    
  7. Ensure that the script is executable # chmod +x /etc/profile.d/nvm.sh
  8. If you want to use nvm in non-interactive sessions as well make sure to source the nvm file in /etc/bash.bashrc before the line saying # If not running interactively, don't do anything by adding . /etc/profile.d/nvm.sh.
  9. For bash completion (which is inherently interactive ;) add [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" after the section about bash completion.

Every user can select a version of node (as the permissions for public are r-x) and users in the nvm group can install and remove versions of node (permissions for the group are rwx).

My questions are:

  • As a developer I know next to nothing about linux, could this be improved, is it bad style, etc? Any feedback is welcome.
  • Should this be documented in the NVM README.md?
@ljharb
Copy link
Member

ljharb commented May 22, 2017

nvm is not intended to be global or system-wide - it's per-user, per-shell-session.

Thus, each user account must have its own $NVM_DIR. They can certainly share an nvm.sh, but I'd recommend they all have their own one of those too.

I would not want to document anything in the readme that encourages people to use nvm across user accounts - there's other tools for that.

@AndreSteenveld
Copy link
Author

AndreSteenveld commented May 22, 2017

There is of course n (with n-install) which with a coaching could do the same. I'll give that a shot and create a gist of the process, what are the possible other tools, other than say apt-get, brew or some system level package manager which you are usable to manager the version of node in your shell?

@ljharb
Copy link
Member

ljharb commented May 22, 2017

Yes, n is the sole system-wide node manager I'd recommend.

However, I'd suggest just installing nvm in the cronjob user, and invoking the cronjobs such that nvm.sh is sourced.

@rtwk
Copy link

rtwk commented May 27, 2017

Yes it is always good to go with what nvm is intended for. per user. Go for per user installation. I have a similar kind of a situation (I used to install node without nvm previously) and did the same.

@Spown
Copy link

Spown commented Jan 11, 2018

nvm is not intended to be global or system-wide - it's per-user, per-shell-session.

You know, for an util that should eliminate version discrepancies and staff it sure does increase it a lot... I mean I have server that deploys web projects on git pushes via hooks (i.e user = git). But sometimes I need to log in and redeploy the same things manually by invoking the git hooks manually (user = me). And sometimes my colleagues have to do the same (user = foo)... And then there is a process manager (PM2) that should be central for everyone, but it relies on node as well...

And everybody have it's own node&npm. Except root, so trying to sudo yields even less results, i.e node: command not found. Ok, your util is the wrong one for these kind of things, but NPM in it's official docs explicitely says to use nvm to avoid permission problems that unavoidably accompany multiuser usage.

@ljharb
Copy link
Member

ljharb commented Jan 11, 2018

Yes - the hazard is "multiuser usage". In your use case, everyone should be running node as the same user.

@hparadiz

This comment has been minimized.

@ljharb ljharb added the root / multiuser issues Anything related to using `sudo` or `su`, or using nvm across multiple user accounts. label Aug 6, 2018
@ljharb

This comment has been minimized.

@hparadiz

This comment has been minimized.

@ljharb

This comment has been minimized.

@grzegorznowak
Copy link

Hey guys,
A bit of heresy from me over here that relates to this thread.
(but let's not launch the Spanish Inquisition (tm) just yet)
We needed properly managed and stable node version on our bespoke in-team-dev machines as well as on some specific live use-cases, and for that have forged an Ansible role to do just that. You may call it a hack, or you may not, it's your free will, but we're using NVM as the drop in replacement for the distro's node package, accessible globally.
NVM turned out to be heavens apart in terms of stability than any apt + n combination we tried. I appreciate the tool (kudos and big thanks to you @ljharb) so it's the solution we incorporated.
For anyone interested (hope you don't mind sharing here bro):
https://github.com/grzegorznowak/ansible-nvm-node

For anyone else, please use the proper user-scoped approach. Whatever floats your servers chaps.

@hparadiz

This comment has been minimized.

@ljharb

This comment has been minimized.

@grzegorznowak

This comment has been minimized.

@hparadiz

This comment has been minimized.

@hparadiz

This comment has been minimized.

@ljharb

This comment has been minimized.

@nvm-sh nvm-sh locked as too heated and limited conversation to collaborators Sep 27, 2018
@ljharb
Copy link
Member

ljharb commented Sep 27, 2018

Please see #1533 (comment) if you have any questions - nvm is not designed for, or intended for, multiple users, and will never support the same.

This issue remains open because there's clearly some documentation change that could be made in the readme to make this more clear. A PR to do so is welcome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
root / multiuser issues Anything related to using `sudo` or `su`, or using nvm across multiple user accounts.
Projects
None yet
Development

No branches or pull requests

6 participants