Vagrant - "Command not found" error

Hi There,

I’m very new to VM’s and using vagrant, so I apologize if there’s additional information that I should have included in this explanation. I’ve installed both virtual box and vagrant onto my MacBook, however, after I input: “vagrant up” and then “vagrant ssh” all other commands don’t work and I get the error message: “-bash: vagrant: command not found”. I’ve tried to solve this problem myself by going through other forums and discussion boards, but haven’t had any luck yet. Any help would be appreciated!!

Hi there,

Just to confirm that I understand your situation currently, you:

  1. Installed VirtualBox
  2. Installed Vagrant
  3. Ran vagrant up (successfully)
  4. Ran vagrant ssh (successfully)
  5. Now vagrant commands result in an error

Based on the above being correct, the issue is likely because you are connected to the Vagrant guest instead of your host system. When running vagrant ssh, Vagrant will create an SSH connection to the guest providing you with a shell on the guest. Once you are in the guest, the vagrant command will not be available as it is not installed on that “machine”.

You should be able to confirm this by opening another terminal window in macOS and running vagrant which should work as expected.

Cheers!

1 Like

Hi Chris!

Thank you so much for reaching out, you’re a lifesaver. Yes, the situation you described is correct.

I followed your instructions and opened up a second terminal and started vagrant, however, I’m still getting the same error of “command not found”.

This is the output that I get when I run: vagrant up

sh: netsh: command not found

sh: cscript: command not found

It seems that you don’t have the privileges to change the firewall rules. NFS will not work without that firewall

changes. Execute the following commands via cmd as administrator:

netsh advfirewall firewall add rule name=“VagrantWinNFSd-1.4.0” dir=“in” action=allow protocol=any program="\Users\alaniwaasa.vagrant.d\gems\2.6.6\gems\vagrant-winnfsd-1.4.0\bin\winnfsd.exe" profile=any

netsh advfirewall firewall add rule name=“VagrantWinNFSd-1.4.0” dir=“out” action=allow protocol=any program="\Users\alaniwaasa.vagrant.d\gems\2.6.6\gems\vagrant-winnfsd-1.4.0\bin\winnfsd.exe" profile=any

If you are an Windows XP user run the following command instead:

netsh firewall add allowedprogram “\Users\alaniwaasa.vagrant.d\gems\2.6.6\gems\vagrant-winnfsd-1.4.0\bin\winnfsd.exe” VagrantWinNFSd-1.4.0 ENABLE

Bringing machine ‘default’ up with ‘virtualbox’ provider…

==> default: Clearing any previously set forwarded ports…

==> default: Clearing any previously set network interfaces…

==> default: Preparing network interfaces based on configuration…

default: Adapter 1: nat

==> default: Forwarding ports…

default: 22 (guest) => 2222 (host) (adapter 1)

==> default: Booting VM…

==> default: Waiting for machine to boot. This may take a few minutes…

default: SSH address: 127.0.0.1:2222

default: SSH username: vagrant

default: SSH auth method: private key

==> default: Machine booted and ready!

[default] GuestAdditions 6.1.16 running — OK.

==> default: Checking for guest additions in VM…

NFS requires a host-only network to be created.

Please add a host-only network to the machine (with either DHCP or a

static IP) for NFS to work.

Based on the output you have provided it looks like your Vagrantfile is assuming you are running on a Windows system, which is why you are getting these errors. You’ll need to remove the Windows specific setups from your Vagrantfile, or just start a new project with a minimal Vagrantfile and then extend it as required. You can easily create a new Vagrant project by starting in a new directory and running: vagrant init hashicorp/bionic64

Cheers