Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating path in Vagrant using shell provisioning

I am using Vagrant to deploy a virtual machine with several installed packages using shell provisioning. One of the packages needs an update of path to be used properly which I wasn't able to do.

These are the contents of my Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"

#config.vm.network "forwarded_port", guest: 8888, host: 8888

config.ssh.forward_agent = true
config.vm.provision "shell", path: "provision.sh" 

end

These are the following things I tried:

  1. Create a separate .bashrc and .profile files with the following commands (appended at the end of file) and copy them into home directory:

    export PATH="/usr/local/x86_64/bin:$PATH"
    
  2. Try to write into .profile file:

    echo 'export PATH="/usr/local/x86_64/bin:$PATH"' >> .profile
    
  3. Just try exporting PATH during the provisioning (i.e. as a line of code in the provision.sh):

    export PATH="/usr/local/x86_64/bin:$PATH"
    

After vagrant up command finishes, this command does enable the change of path following vagrant ssh.

like image 329
Matt Avatar asked Feb 10 '14 21:02

Matt


1 Answers

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_profile
grep 'PATH=/usr/local/x86_64/bin' ~/.profile || echo 'export PATH=/usr/local/x86_64/bin:$PATH' | tee -a ~/.profile
grep 'PATH=/usr/local/x86_64/bin' ~/.bash_profile || echo 'export PATH=/usr/local/x86_64/bin:$PATH' | tee -a ~/.bash_profile
. ~/.profile
. ~/.bash_profile
echo PATH $PATH

This works for the precise 64 box all the commands should be one line.

like image 58
Matt Avatar answered Nov 12 '22 06:11

Matt