VirtualBox7とVagrantをubuntu(CUI)にインストール、アップデート

スポンサーリンク

最近、VirtualBox7がリリースされたのでVagrantとセットでインストールします。このPCには古いVirtualBoxがインストールしてあるはずですが念のため確認します。

dpkg -l | grep virtualbox

6.1がインストール済みでした。Windowsの時と同じようにVirtualBoxのインストールコマンドを入力すると7がインストールされるだろうと思ったのでコマンドを入力します。

apt install virtualbox

しかし、実際にインストールされたのは6.1のアップデート版でした。そこで公式からダウンロードしてインストールすることにします。

Oracle VM VirtualBox
wget コピーして取得したURL
dpkg -i ダウンロードしたファイル名

下記のようなエラーが発生してインストールすることができません。

以前に未選択のパッケージ virtualbox-7.0 を選択しています。
dpkg: virtualbox-7.0 を選択するために virtualbox の削除を考えています …
dpkg: no, cannot proceed with removal of virtualbox (–auto-deconfigure will help):
virtualbox-qt は virtualbox (= 6.1.38-dfsg-3~ubuntu1.22.04.1) に依存 (depends) します
virtualbox は削除されようとしています。

dpkg: virtualbox-7.0_7.0.0-153978~Ubuntu~jammy_amd64.deb が virtualbox-7.0 を含 んでいることを考慮すると:
virtualbox-7.0 は virtualbox と競合 (conflicts) します
virtualbox (バージョン 6.1.38-dfsg-3~ubuntu1.22.04.1) が提供され、導入済み で す。

dpkg: アーカイブ virtualbox-7.0_7.0.0-153978~Ubuntu~jammy_amd64.deb の処理中にエラーが発生しました (–install):
パッケージの競合 – virtualbox-7.0 のインストールは行いません
処理中にエラーが発生しました:
virtualbox-7.0_7.0.0-153978~Ubuntu~jammy_amd64.deb

やはり、古いVirtualBoxを削除してからでないとインストールはできないみたいです。削除するコマンドを入力します。

apt remove --purge virtualbox

再びVirtualBox7のインストールコマンドを入力します。

dpkg -i ダウンロードしたファイル名

(データベースを読み込んでいます … 現在 146255 個のファイルとディレクトリがインストールされています。)
virtualbox-7.0_7.0.0-153978~Ubuntu~jammy_amd64.deb を展開する準備をしています …
virtualbox-7.0 (7.0.0-153978~Ubuntu~jammy) を展開しています…
dpkg: 依存関係の問題により virtualbox-7.0 の設定ができません:
virtualbox-7.0 は以下に依存 (depends) します: libqt5help5 (>= 5.15.1) …しかし:
パッケージ libqt5help5 はまだインストールされていません。
virtualbox-7.0 は以下に依存 (depends) します: libqt5xml5 (>= 5.0.2) …しかし:
パッケージ libqt5xml5 はまだインストールされていません。

dpkg: パッケージ virtualbox-7.0 の処理中にエラーが発生しました (–install):
依存関係の問題 – 設定を見送ります
hicolor-icon-theme (0.17-2) のトリガを処理しています …
shared-mime-info (2.1-2) のトリガを処理しています …
処理中にエラーが発生しました:
virtualbox-7.0

不足していると指摘のあるパッケージをインストールします。

apt install libqt5help5 libqt5xml5

パッケージリストを読み込んでいます… 完了
依存関係ツリーを作成しています… 完了
状態情報を読み取っています… 完了
これらを直すためには ‘apt –fix-broken install’ を実行する必要があるかもしれません。
以下のパッケージには満たせない依存関係があります:
libqt5help5 : 依存: libqt5sql5 (>= 5.3.0) しかし、インストールされようとしてい ません
E: 未解決の依存関係です。’apt –fix-broken install’ を実行してみてください (または解法を明示してください)。

エラーが発生しました。メッセージに表示されたコマンドを入力します。

apt --fix-broken install

その後、再びVirtualBoxのインストールを試みましたが、直前のコマンドで解決されたようです。インストールされたVirtualBoxのバージョンを確認します。

VBoxManage -v

正常にVirtualBox7がインストール出来たようです。Vagrantはインストール済なので仮想マシンが正常に起動するか確認します。インストール方法は公式に記載されています。

Vagrant by HashiCorp
Vagrant enables users to create and configure lightweight, reproducible, and portable development environments.

rootで作業している時は、sudoを取り除いてコマンドを実行します。

wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/hashicorp.list
apt update && apt install vagrant

インストール済みのVagrantのバージョンを確認します。

vagrant version

仮想マシンを起動して動作確認します。

vagrant up

しかしエラーが発生しました。

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 has detected that you have a version of VirtualBox installed
that is not supported by this version of Vagrant. Please install one of
the supported versions listed below to use Vagrant:

4.0, 4.1, 4.2, 4.3, 5.0, 5.1, 5.2, 6.0, 6.1

A Vagrant update may also be available that adds support for the version
you specified. Please check www.vagrantup.com/downloads.html to download
the latest version.

Vagrantをダウンロードして、手動で最新バージョンをインストールすることにします。このバージョンはVirtualBox7をサポートしているとのことです。

rpm -Uvh https://releases.hashicorp.com/vagrant/2.3.2/vagrant-2.3.2-1.x86_64.rpm

RPMが無いのでインストールします。

apt install rpm

vagrantのインストール後にバージョンを確認すると以下のメッセージが表示されました。

Vagrant failed to initialize at a very early stage:

The plugins failed to initialize correctly. This may be due to manual
modifications made within the Vagrant home directory. Vagrant can
attempt to automatically correct this issue by running:

vagrant plugin repair

If Vagrant was recently updated, this error may be due to incompatible
versions of dependencies. To fix this problem please remove and re-install
all plugins. Vagrant can attempt to do this automatically by running:

vagrant plugin expunge –reinstall

Or you may want to try updating the installed plugins to their latest
versions:

vagrant plugin update

Error message given during initialization: Unable to resolve dependency: user requested ‘vagrant-vbguest (= 0.30.0)’

プラグインの修復、再インストール、もしくは更新をすれば解決できるようです。修復で失敗したので更新をすると正常にバージョンを確認できました。

再び仮想マシンが立ち上がるか確認します。しかし、フリーズして起動しません。古いVirtualBoxの削除方法が適切ではなかったようです。次のコマンドで削除すると仮想マシンが正常に起動しました。

apt remove virtualbox*

アンインストールできない時はサービスを停止します。さらにこのサービスのプロセスIDを探し出し、プロセスを終了します。

service vboxdrv stop
pidof VBoxSVC
kill -9 表示されたPID番号
タイトルとURLをコピーしました