WSL 環境で vagrant up した時に 'Vagrant could not detect VirtualBox!' というエラー

VBoxManage という実行ファイルが見つからないというメッセージ

The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:

Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
Vagrant uses the `VBoxManage` binary that ships with VirtualBox, and requires
this to be available on the PATH. If VirtualBox is installed, please find the
`VBoxManage` binary and add it to the PATH environmental variable.

 

前提条件

  • WindowsVirtualBoxはインストールされている

  • 下記の記述は~/.bashrcに書かれている

export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"

# VirtualBoxのパス
PATH=$PATH:"/mnt/c/Program Files/Oracle/VirtualBox"

下記のコマンドに対して次のように反応する

$ VBoxManage --version
プログラム 'VBoxManage' はまだインストールされていません。 次のように入力することでインストールできます:
sudo apt install virtualbox
# 拡張子をつけると反応する(パスは通っている)
$ VBoxManage.exe --version
6.0.12r133076

 

解決した方法

下記のように実行すると期待通りの動作をする。

 vagrant.exe up

Vagrantが拡張子を確認するようになる?

とりあえず毎回.exeとつけるのも面倒なのでエイリアスを設定する。
下記のように~/.bashrcに追記する

alias vagrant='vagrant.exe'

コマンドで実行

cat <<EOF >> ~/.bashrc
alias vagrant='vagrant.exe'
EOF