I may have a problem in the include chain for the profiles, or something may be awry in either my system, or my understanding of profile.d (RHEL7).

I added a /etc/profile.d .sh script which is for a node installation, whilst trying to clean up the .bashrc. The problem is that it is not appending to the $PATH like I had hoped.

Note, the issue is happening both via my main terminal (ssh via putty), but also directly from the console itself as well.

$ cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc

$ cat /etc/profile.d/nvm_path.sh
# This adds node/nvm(node version manager) to path, and then initializes nvm, and its bash completion

#Load NVM
if [ -f ~/.nvm ]; then

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

    if [ -f $NVM_DIR/bash_completion ]; then

        [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# Force npm onto the path (only needed if its not available on your node installation)
if [ -f ~/.npm/ ]; then

# Include node_mod bins in PATH, which are usually symlinked here (gulp,
# cordova, etc..)
if [ -f $HOME/.npm-packages/bin ]; then

    #note is a hyphen, not an underscore

export PATH

For /etc/profile itself, its my understanding the perms are ok as read-only since they are sourced, as opposed to executed, so i think this isnt an issue. -rw-r--r--. 1 root root 1795 May 4 2016 profile

What have i missed?

I'm thinking the problem is somewhere along the lines of since the scripts are initially loaded by root the paths are invalid. The problem: where I try to load the user paths. What can be done about this? Do I need to add in a $LOGGED_USER variable in place of if [ -f ~/.nvm ] and maybe even $HOME? What is that variable?

After further research, it appears the problem is that root is loading the script, so $HOME, even $USER, is never available, even if I set a condition in there to check if root is loading or not, since root is always sourcing the script.

if [[ $EUID -ne 0 ]]; then

if [ -f $USERDIR/.nvm ]; then

I would need to have the var check happen once the user logs in, not when root sources it.

It appears something like this is destined for /etc/skel/.bash_profile, unless someone comes up with a clever bash script idea. Any ideas on how to accomplish this here, so that I don't have to use /etc/skel?

  • 1
    Does that NVM_DIR variable get set properly? Check that you don't have some other place in the shell's init scripts that would reset PATH. – ilkkachu May 11 '17 at 22:59
  • Good call. Wouldn't I check jsut check that using $ env? I see no mention of it. Do you think its because of the -f ~/.nvm doesn't exist for root since I'm checking it against user "~"? – Brian Thomas May 11 '17 at 23:10
  • 2
    -f checks for a regular file, -d checks for a directory. – Kusalananda May 11 '17 at 23:48
  • Ok, that solved it. I thought it was the file check at first, just didn't catch that. Add as an answer please. Maybe just copy and paste my whole script there, and correct to the -d since it seems really useful for node path drop-in solution. $ which gulp ~/.npm-packages/bin/gulp – Brian Thomas May 11 '17 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.