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
This is probably because you have an
env_reset
directive in your sudoers(5) file.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.