question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

~/.bash_profile not being loaded?

See original GitHub issue

Hey there, not sure if this is the best place to ask but I thought I’d try.

I just setup a basic micro instance on EC2 on ubuntu 12.04, and then installed node like this (modified from here):

sudo apt-get update
sudo apt-get install build-essential -y
sudo apt-get install g++ make libssl-dev git-core pkg-config
mkdir ~/local
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bash_profile
. ~/.bash_profile

# Download Source for Node
mkdir ~/src
cd ~/src
git clone git://github.com/joyent/node.git

# Install Node:
cd ~/src/node
git checkout v0.10.17
./configure --prefix=~/local
make install

When I ssh into the instance and run node -v, it prints v0.10.17 as expected. I ssh like this:

ssh -i path/to/key.pem ubuntu@ec2-123-123-123-123.compute-1.amazonaws.com

But when I try to do the same thing using this ssh2 module, it prints:

bash: node: command not found

The main difference between the two is this: when I ssh -i ..., it takes me to an interactive shell, whereas with node’s ssh2 module I am executing the command (rather than running an interactive shell, I think, (exec vs. shell methods)). The strange thing is, using either method, if I cat ~/.bashrc, they both are exactly the same. The last thing is, I can successfully execute the node -v command on ssh2 if I add source ~/.bash_profile before, so:

source ~/.bash_profile ; node -v

The original install script echoed the PATH to ~/.bashrc, but I modified it to ~/.bash_profile because that was the only thing that seemed to work (along with adding the source ~/.bash_profile to the command).

Any ideas why this is happening? Is this something to do with ssh2 and ubuntu, or is this an issue with the node module?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
mscdexcommented, Feb 19, 2014

@pkyeck You may have to check your .bashrc. At least on Ubuntu, .bashrc will exit early if it detects that it’s not being run in interactive mode:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

You could try just setting PS1 before sourceing .bashrc:

conn.exec("PS1='\u@\h:\w\$ ' source ~/.bashrc; echo Hooray", function(err, stream) {
  // ...
});
0reactions
gdraganiccommented, Mar 21, 2016

@mscdex Didn’t work for me even with pty enabled, this was my case:

conn.exec("set -i && source ~/.bashrc && " + command, {
  pty: true 
}, function(err, stream) {
  //...
});

This is the begging of my .bashrc file:

# If not running interactively, don't do anything                                                                                                                    
case $- in                                                                                                                                                           
    *i*) ;;                                                                                                                                                          
      *) return;;                                                                                                                                                    
esac 

Setting the interactive flag before source-ing the .bashrc file was the only way to do it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why ~/.bash_profile is not getting sourced when opening a ...
~/.bash_profile is only sourced by bash when started in login mode. That is typically when you log in at the console ( Ctrl...
Read more >
Bash .profile not loading - Stack Overflow
Stumbled on this thread when reverting from Mac OSX Catalina "upgrade" of zsh back to bash. Turns out ~/.bash_profile isn't used, and only...
Read more >
Why doesn't my ~/.bash_profile work? - Unix Stack Exchange
After I start my graphical desktop environment and run a terminal emulator from it, I can see that .bash_profile is not sourced (environment ......
Read more >
centos - .bash_profile not being read - Server Fault
bashrc is read just fine and if I do source ~/.bash_profile FOO is created as well as my $PATH being edited properly but...
Read more >
macOS .bash_profile Not Being Sourced in Terminal
Find out why .bash_profile file is not is not being sourced in a macOS zsh shell.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found