-1

I am running the following script from a Vagrantfile and everything is working fine. In the end, I see the output go1.10 linux/amd64 as expected.
But, when I run vagrant ssh I get The program 'go' is currently not installed.

What is the difference between vagrant provision that was able to see go and vagrant ssh that was not able to see go?

config.vm.box = "ubuntu/xenial64"
config.vm.provision "shell" do |s|

     s.inline = "
                sudo apt-get update 

                export GOPATH=$HOME/work
                sudo curl -O https://storage.googleapis.com/golang/go1.10.linux-amd64.tar.gz
                sudo tar -xvf go1.10.linux-amd64.tar.gz
                sudo mv go /usr/local

                sudo echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
                export PATH=$PATH:/usr/local/go/bin
                go version" # this row is working fine on the script but not after ssh

   end
Cosmic Ossifrage
  • 4,977
  • 29
  • 30
SexyMF
  • 10,657
  • 33
  • 102
  • 206
  • 1
    Is the provisioning script run under the same user you SSH into? If not, add the `PATH` to `/etc/profile` instead of `~/.profile` – mhutter Sep 13 '18 at 22:20
  • @mhutter I don't know. This is new to me. I just run vagrant ssh – SexyMF Sep 14 '18 at 04:53
  • Find out by adding `id` or `whoami` to the script ;-) – mhutter Sep 14 '18 at 05:51
  • @mhutter the user running the provision is root. and the user im using is vagrant - what sould i do? I want go to be available for all users. – SexyMF Sep 14 '18 at 10:40
  • Possible duplicate of [Golang installation](https://stackoverflow.com/questions/50554817/golang-installation) – mbuechmann Sep 14 '18 at 13:10

1 Answers1

1

In order to make your changes to $PATH available to all users, you have to change it in the global profile, not the user's. Change the line

sudo echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile

to

sudo echo 'export PATH=$PATH:/usr/local/go/bin' >> /etc/profile
mhutter
  • 2,800
  • 22
  • 30