2

I have a makefile, which I use to sudo make install for the parts of my app that generally require root installation. Unfortunately, this results in a strange situation where sudo doesn't have access to npm, while both root and my user do have access:

self:

$ which npm /home/self/.nvm/versions/node/v5.9.1/bin/npm 

Root:

$ sudo su - root@theserver~# which npm /root/.nvm/versions/node/v5.9.1/bin/npm 

exit

$ sudo which npm $ (that's a blank line, sudo which npm gives no result)

How do I resolve this discrepancy? What am I missing about the npm ecosystem that would allow me to do this differently?

I'm running Ubuntu 14.04 LTS:

cat /proc/version cat /etc/issue uname -a Linux version 3.13.0-44-generic (buildd@lamiak) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014 Ubuntu 14.04.4 LTS \n \l Linux theserver 3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux 

PATH and HOME of standard user and root.

user@server:~$ cat ~/.profile # ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. # see /usr/share/doc/bash/examples/startup-files for examples. # the files are located in the bash-doc package. # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022 # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi # set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi user@server:~$ sudo echo $PATH $HOME /home/user/.nvm/versions/node/v5.9.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games /home/user user@server:~$ echo $PATH $HOME /home/user/.nvm/versions/node/v5.9.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games /home/user user@server:~$ sudo su root@server:/home/user# echo $PATH $HOME /root/.nvm/versions/node/v5.9.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games /root root@server:/home/user# cat ~/.profile # ~/.profile: executed by Bourne-compatible login shells. if [ "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc fi fi mesg n 
1
  • Please print $PATH and $HOME in each environment in order to debug. Also the contents of *.profile of both users might be useful. Commented Mar 29, 2016 at 13:21

1 Answer 1

3

This is probably because you have an env_reset directive in your sudoers(5) file.

By default, the env_reset option is enabled. This causes commands to be executed with a new, minimal environment...

That minimal environment does not contain a PATH. The Command Environment section of the sudoers(5) man pages has lots of relevant information for you to peruse.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.