I am trying to automate VM configuration with a script and am having some trouble getting access to some path variables that get set in either ~/.bashrc
, ~/.bash_profile
, or ~/.profile
.
My remote VM is running ubuntu 14.04 LTS and I am deploying over ssh.
This is the array that gets joined together to be run as a bash command to configure the vm by installing nvm:
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" >> ~/.bash_profile
].join('\n');
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" >> ~/.bash_profile`
].join('\n');
But when when I run the next script that actually installs node and yarn, it cannot find nvm
:
return [
`nvm install ${config.node.version}`,
`nvm use ${config.node.version}`,
`echo "using node $(node -v) and npm $(npm -v)"`,
`curl -o- -L https://yarnpkg.com/install.sh | bash`,
'echo "export PATH="$HOME/.yarn/bin:$PATH"" >> ~/.bash_profile',
].join('\n');
This is the error: bash: nvm: command not found
bash: line 1: nvm: command not found`
I don't want to ssh in and manually add anything to any of the various profiles. I'd like it all to be done by the script. I also want to avoid sourcing ~/.nvm/nvm.sh
or sourcing any of the profiles when the ssh session begins. I was under the impression that an ssh session automatically sources ~/.bash_profile
, which should then read from those variables correct? If not, then how else can I configure my deployment script to automatically have access to these variables?
Based on the fact that you are using && as you said in your comments I would add a line to actually
source ~/.nvm/nvm.sh
before running thenvm
commands. You likely don't have the command available at the shell until that has been run.Change this:
To this: