Jul 27th 2015When sourcing `.bashrc` in a Vagrant provisioning script doesn't work

I was trying to use n in a provisioning script for a Vagrant box to install node.js. There is a really handy install script called n-install and I had decided to go with that to install any version of node.js/io.js in one line like this:

# install io.js
curl -L http://git.io/n-install | bash -s -- -y io:latest
source $HOME/.bashrc

I had to source the .bashrc to set some environment variables for n and add it to the PATH. This never worked and I couldn't figure out why until I opened an issue on GitHub and found a StackOverflow post mentioning a potential issue.

The problem is that the default .bashrc contains this line at the very top:

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

So the relevant lines that setup n never get executed. I have found this to be the case for ubuntu/precise64 and ubuntu/trusty64 boxes.

I haven't found a way to source the .bashrc without breaking anything, so I am going to be using a different install method for n in the meantime. If I make a discovery, I will update this post.