Updating path in Vagrant using shell provisioning
The problem was resolved with the following added to the provision.sh
file based on this post:
echo PATH $PATH[ -f ~/.profile ] || touch ~/.profile[ -f ~/.bash_profile ] || touch ~/.bash_profilegrep 'PATH=/usr/local/x86_64/bin' ~/.profile || echo 'export PATH=/usr/local/x86_64/bin:$PATH' | tee -a ~/.profilegrep 'PATH=/usr/local/x86_64/bin' ~/.bash_profile || echo 'export PATH=/usr/local/x86_64/bin:$PATH' | tee -a ~/.bash_profile. ~/.profile. ~/.bash_profileecho PATH $PATH
This works for the precise 64 box all the commands should be one line.
Example using Ex/vi editor:
ex +'$s@$@\rexport PATH=/var/lib/vendor/bin:$PATH@' -cwq /etc/bash.bashrc
which appends:
export PATH=/var/lib/vendor/bin:$PATH
into global /etc/bash.bashrc
file (so it's available for all users using bash
shell, or use /etc/profile
to use for all Bourne shells).
Alternatively use simply cat
, e.g.:
cat >> ~/.bashrc <<EOFexport PATH=~/.composer/vendor/bin:\$PATHEOF
If you need to have access to newly tool straight away, then you need to source
the file.
If you're using composer
, you may consider installing the binaries by specifying the requirements in composer.json
, see some examples here, so in this case, you don't have to worry about configuring PATH variable.
If you're using Ansible playbooks, you can try using Files Modules with the following rule in yml file:
- name: Update bashrc to add new PATH entry: dest=/home/vagrant/.bashrc line="export PATH='/usr/local/x86_64/bin:$PATH'" regexp="^export PATH" owner=vagrant state=present insertafter=EOF create=True