These are chat archives for creationix/nvm

6th
Jan 2017
Varun Jayaraman
@varunjayaraman
Jan 06 2017 21:09
hey guys, not sure if this gitter is still alive or not
i'm having some trouble sourcing ~/.nvm/nvm.sh when sshing into my remote instance
this is probably more of a bash problem than it is nvm, but was wondering if anyone has experienced this problem where you have to manually source ~/.nvm/nvm.sh in an ssh session to get access to nvm.
(my remote VM is Ubuntu 14.04)
Jordan Harband
@ljharb
Jan 06 2017 22:05
@varunjayaraman when you ssh in, are you requesting a login shell?
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:06
nope, unless the npm module ssh2 does that
oh wait i think that would be requesting a login shell right
i thought ssh usually is through a login shell, so it wouldnt use bashrc, but bash_profile
but i actually put some echoes in those files and it seems like .bashrc is running when i ssh in
@ljharb this is the set of commands that im running as a bash command after the array gets joined together by newlines:
return [
      `rm -rf ~/.nvm`,
      `sudo apt-get update`,
      `sudo apt-get install -y build-essential libssl-dev`,
      `curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh`,
      `bash install_nvm.sh`,
      `echo "source ~/.nvm/nvm.sh" >> ~/.bashrc`
    ].join('\n');
Jordan Harband
@ljharb
Jan 06 2017 22:08
usually you'd add a line to bash_profile that sources bashrc
also you don't need to rm ~/.nvm :-)
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:09
yeah normally i wouldnt
Jordan Harband
@ljharb
Jan 06 2017 22:09
you can keep it there and the install script and nvm install will have to do less work
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:09
its just i want a completely fresh start while im testing the script
Jordan Harband
@ljharb
Jan 06 2017 22:09
ok
so if bashrc is definitely getting sourced, then nvm should be available in the shell session
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:09
yeah thats what i thought
because i see that nvm adds that part to the bottom
of bashrc
Jordan Harband
@ljharb
Jan 06 2017 22:10
right - a) if bashrc is getting sourced and b) the command is in bashrc, and c) the command works when typed directly into the shell, it must logically be working
so if it's not i dunno :-/
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:10
export NVM_DIR="/home/ubuntu/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
so that gets sourced as part of the bashrc file
Jordan Harband
@ljharb
Jan 06 2017 22:10
that should work fine
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:11
if i put an echo right above that, it should say its running when the 2nd script runs
Jordan Harband
@ljharb
Jan 06 2017 22:11
assuming $HOME is /home/ubuntu
and you're sure nothing is modifying the PATH after nvm is sourced?
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:11
yeah
Jordan Harband
@ljharb
Jan 06 2017 22:11
like, what's echo $PATH and type nvm print out?
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:11
should i echo it right after that
Jordan Harband
@ljharb
Jan 06 2017 22:11
(when it doesn't work)
oh no i mean, run that on the terminal
after everything's loaded and it theoretically should be working but isnt
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:12
ah ok
one sec
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
thats $PATH
hmm
and obviously type nvm is not found because nvm isnt in the PATH
Jordan Harband
@ljharb
Jan 06 2017 22:15
right, it wouldn't be in the path unless you had a node version installed
type nvm should work because nvm is a sourced shell function, not a binary
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:15
ah ok
if i manually source ~/.nvm/.sh this works
but i dont want to do that
Jordan Harband
@ljharb
Jan 06 2017 22:17
right, you shouldn't have to
but it's heartening that it does work
because that means it's just a problem with "the things getting sourced" and "the shell session you end up in"
is there any chance the session you ssh into isn't the one you end up in?
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:17
so i took out that last line that appends sourcing ~/.nvm/nvm.sh to .bashrc
Jordan Harband
@ljharb
Jan 06 2017 22:17
like, do you su anywhere?
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:17
nope
Jordan Harband
@ljharb
Jan 06 2017 22:17
and there's no subshell anywhere?
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:17
its microsoft azure
Jordan Harband
@ljharb
Jan 06 2017 22:17
or screen
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:18
so you cant even get into root or anything
Jordan Harband
@ljharb
Jan 06 2017 22:18
i don't know anything about azure
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:18
basically they prevent root access
completely
so right now its the only user i set up with sudo access
ubuntu
oh i see what you mean, i dont think theres a subshell
is there a way to tell?
Jordan Harband
@ljharb
Jan 06 2017 22:19
probably just reading docs :-/
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:19
looks like if i echo echo $SHLVL
it tells you
Jordan Harband
@ljharb
Jan 06 2017 22:20
ok
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:20
shell level is 1
Jordan Harband
@ljharb
Jan 06 2017 22:20
TIL
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:21
:/
yeah shell levl is 1 in both
hm, do you have an example of a sample deployment script that installs nvm
or do you normally do that manually
i dont mind doing it manually, it takes like 2 seconds
Jordan Harband
@ljharb
Jan 06 2017 22:23
installing nvm i usually do manually, yes
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:23
i just like the convenience of typing one command and having all this shit done for me
Jordan Harband
@ljharb
Jan 06 2017 22:23
that should be fine tho
ohhh wait
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:23
!!!
Jordan Harband
@ljharb
Jan 06 2017 22:23
you run that command upon logging in?
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:23
do tell
which one, the 1st or 2nd
Jordan Harband
@ljharb
Jan 06 2017 22:23
the time it doesn't work
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:23
so every time :D
Jordan Harband
@ljharb
Jan 06 2017 22:24
what i mean is, are you re-sourcing bashrc after you modify it
bashrc gets sourced before you run anything
in other words, add . $HOME/.bashrc to your command list
and see what happens
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:24
no im not
Jordan Harband
@ljharb
Jan 06 2017 22:24
so there you go
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:24
but the 2nd command is a second ssh script
Jordan Harband
@ljharb
Jan 06 2017 22:24
you're never actually sourcing nvm
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:24
like this ssh session ends
and a new one is created
for the 2nd set of commands
Jordan Harband
@ljharb
Jan 06 2017 22:24
hm
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:24
i still have to source it?
Jordan Harband
@ljharb
Jan 06 2017 22:25
and you're certain bashrc is being sourced the 2nd time around?
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:25
yeah i put an echo in there
Jordan Harband
@ljharb
Jan 06 2017 22:25
try adding one of those "echo" statements inside your command list
instead of directly inside bashrc
the question is, is bashrc being sourced after you've modified it
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:26
sorry im a bit confused
what do you want me to echo in the command list
oh you mean any echo, to see which runs first?
Jordan Harband
@ljharb
Jan 06 2017 22:26
echo "echo sourcing && source ~/.nvm/nvm.sh" >> ~/.bashrc`
iow i want the thing you add to be "echo something and then source nvm"
so that you can see if the thing you added is being executed
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:28
at the end of the 1st command list?
like where in the timeline do you want to see this echo
Jordan Harband
@ljharb
Jan 06 2017 22:30
in that array
where you do your apt-get update and whatnot
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:31
ok i put this command in the array
echo "echo sourcing && source ~/.nvm/nvm.sh" >> ~/.bashrc
that will add that stuff to .bashrc though
do you want to see it in the terminal or in .bashrc
anyway those echoes dont get executed
this is the bottom part of my bashrc
export NVM_DIR="/home/ubuntu/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm


echo sourcing && source ~/.nvm/nvm.sh
source ~/.nvm/nvm.sh

export PATH="$HOME/.yarn/bin:$PATH"
export PATH=/home/ubuntu/.yarn/bin:/usr/local/sbin:/usr/local/bin$
(yarn is part of the 2nd script)
Jordan Harband
@ljharb
Jan 06 2017 22:39
ok
if the "echo sourcing" isn't running tho then it's definitely not sourcing your .bashrc on every ssh
aha another hunch
your first ssh requests a login shell, but does your second?
it's like ssh -L or something, and you'd need it on every ssh command you run
(or at least on the last one)
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:45
it should be whatever the npm library ssh2 requests
i'll look inside the source code
but i think i'm just gonna manually configure nvm
that's literally the only part breaking my entire script that allows me to configure my vm with a one-liner and i have to ssh in to configure the ssh keys in .ssh/authorized_keys, it's not too hard to run that one other line to install nvm
Jordan Harband
@ljharb
Jan 06 2017 22:46
gotcha
Varun Jayaraman
@varunjayaraman
Jan 06 2017 22:46
thanks for all the help though
Jordan Harband
@ljharb
Jan 06 2017 22:47
np, good luck