0

I'm using this vagrantfile:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "ubuntu/trusty64"

  ...bla bla bla bla bla...

    config.vm.provision "shell", path: "provision/setup.sh"

end

Since I want to install Linuxbrew I have in my provision/setup.sh this code:

sudo apt-get update

sudo apt-get install --yes git-all libreadline-dev build-essential curl git m4 python-setuptools ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"

# or maybe also this: (but nothing anyway):
# sudo git clone https://github.com/Linuxbrew/linuxbrew.git /home/vagrant/.linuxbrew

export PATH=$HOME/.linuxbrew/bin:$PATH

brew doctor

But I retrieve errors:

==> default: /tmp/vagrant-shell: line 35: brew: command not found

How to fix this?

2 Answers2

1

Let me guess. Add yes before the ruby command

yes | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
BMW
  • 42,880
  • 12
  • 99
  • 116
  • Now it says: `==> default: Don't run this as root! ==> default: /tmp/vagrant-shell: line 35: brew: command not found` –  Feb 03 '16 at 13:18
  • @JohnSam - Would love to hear if a solution was ever found to this. – Zach Folwick Mar 19 '18 at 20:35
1

There's an issue how you run your script - as you run with config.vm.provision "shell", path: "provision/setup.sh" vagrant will run it as root user and so you do not need sudo

however you should really run it as your user so do config.vm.provision "shell", path: "provision/setup.sh", privileged: false

also the export will not be saved for your future session so add it to .bashrc file something like echo PATH=$HOME/.linuxbrew/bin:$PATH >> .bashrc so the final script would look like

sudo apt-get update
sudo apt-get install --yes git-all libreadline-dev build-essential curl git m4 python-setuptools ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev

yes | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"

echo PATH=$HOME/.linuxbrew/bin:$PATH >> ~/.bashrc    
export PATH=$HOME/.linuxbrew/bin:$PATH
brew doctor

The export is needed if you run brew from the script but note that brew doctor will likely ends up with warning and do not return so you might end up seeing vagrant message as

The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

and finally for the original error, @BMW gets all credit adding yes | to the command will default the enter key on the question

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • And if I wanna run everything as root and just linuxbrew as "vagrant" normal user? –  Feb 03 '16 at 13:42
  • honestly I never did this way but I guess `su -l vagrant -c "brew doctor"` would work; in this case also make sure if you do the echo thing to have full path otherwise it will go to root – Frederic Henri Feb 03 '16 at 13:48
  • Anyway, also with `privileged: "false"` in Vagrantfile I get: `==> default: Don't run this as root!` and it down't work! –  Feb 03 '16 at 13:58
  • sorry - remove the quote, must be privileged: false so it is the value false and not a string – Frederic Henri Feb 03 '16 at 14:03
  • Ok, before your accept answer... Now it works, but I can't fix brew in bash. I try this: `echo PATH $PATH [ -f ~/.bashrc ] || touch ~/.bashrc grep 'PATH=/home/vagrant/.linuxbrew/bin' ~/.bashrc || echo 'export PATH=$HOME/.linuxbrew/bin:$PATH' | tee -a ~/.bashrc echo 'export PATH="$HOME/.linuxbrew/bin:$PATH"' >> ~/.bashrc . ~/.bashrc echo PATH $PATH brew doctor ` it says to me: `==> default: /tmp/vagrant-shell: line 30: brew: command not found` –  Feb 03 '16 at 16:22
  • editing answer as the simple `echo PATH=$HOME/.linuxbrew/bin:$PATH >> ~/.bashrc` is working for me – Frederic Henri Feb 03 '16 at 16:54
  • Last question, I swear. I'm trying to launch `gem install bundler` from setup.sh. So I need to change directory with `cd` to install it in `/vagrant` and i'm trying with: `echo 'alias goHome="cd /vagrant"' >> .bashrc` then `. ~/.bashrc` and then `goHome` and then `gem install bundler`, but I have this error: ` /tmp/vagrant-shell: line 76: goHome: command not found ==> default: ERROR: While executing gem ... (Errno::EACCES) ==> default: Permission denied - /var/lib/gems`. What to do? –  Feb 03 '16 at 23:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102571/discussion-between-john-sam-and-frederic-henri). –  Feb 04 '16 at 09:49
  • you need to install with sudo `sudo gem install bundler` will work – Frederic Henri Feb 04 '16 at 13:34
  • Nope, because it install it in ruby -v 1.9 which is the default "system" version. Not rbenv 2.3.0 that I install with `rbenv install 2.3.0` and `rbenv global 2.3.0` and `rbenv local 2.3.0` before `sudo gem install bundler`. And why I need sudo if in `vagrant ssh` I use only `gem install bundler` in rbenv 2.3.0? –  Feb 04 '16 at 13:57
  • at this stage, I think you'll be better off making a new question to ruby community and make sure you describe all the things you installed – Frederic Henri Feb 04 '16 at 14:09