你可能已經下載了多個版本的 Vagrant box,其中一些可能已經過時了。如果您不再需要它們,您可以安全地刪除 Linux 中已棄用的 Vagrant 框,如本簡短指南中所述。
檢查舊的流浪者框
我在用 流浪漢 過去幾個月用於測試目的。 從 Vagrant 1.5 版開始,box 支持版本控制。 Box 版本控制允許創建 Box 的開發人員推送更新或修復,並且用戶可以輕鬆更新底層 Box。
當該框過期時,用戶將在啟動 vagrant 環境時收到通知。 vagrant up
命令:
$ vagrant up
樣本輸出:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'generic/alpine38' version '3.1.16' is up to date...
==> default: A newer version of the box 'generic/alpine38' for provider 'virtualbox' is
==> default: available! You currently have version '3.1.16'. The latest is version
==> default: '3.1.22'. Run `vagrant box update` to update.
==> default: Clearing any previously set forwarded ports...
...
用戶還可以在他們當前的 Vagrant 環境中手動檢查過時的框。 vagrant box outdated
命令:
$ vagrant box outdated
此命令顯示需要更新的框列表。
Checking if box 'generic/alpine38' version '3.1.16' is up to date...
A newer version of the box 'generic/alpine38' for provider 'virtualbox' is
available! You currently have version '3.1.16'. The latest is version
'3.1.22'. Run `vagrant box update` to update.
如果要檢查所有已安裝的框,只需添加 --global
標誌在最後:
$ vagrant box outdated --global
樣本輸出:
/usr/share/rubygems-integration/all/gems/vagrant-2.2.6/plugins/commands/box/command/outdated.rb:65: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /usr/share/rubygems-integration/all/gems/vagrant-2.2.6/lib/vagrant/box.rb:124: warning: The called method `load_metadata' is defined here * 'oraclelinux/8' for 'libvirt' (v8.3.183) is up to date * 'oraclelinux/7' for 'virtualbox' is outdated! Current: 7.9.184. Latest: 7.9.185 * 'generic/alpine38' for 'virtualbox' is outdated! Current: 3.1.16. Latest: 3.1.22 * 'fedora33' for 'virtualbox' wasn't added from a catalog, no version information * 'archlinux/archlinux' for 'virtualbox' is outdated! Current: 20201215.11392. Latest: 20210115.13749 * 'archlinux/archlinux' for 'virtualbox' is outdated! Current: 20201201.10292. Latest: 20210115.13749 * 'Fedora33' for 'libvirt' wasn't added from a catalog, no version information
正如您在上面的輸出中看到的,有一些舊框。
用戶可以使用以下命令更新與其當前 Vagrant 環境關聯的框:
$ vagrant box update
上述命令將下載並安裝新版本的 box。所有下載的盒子都將保存在 ~/.vagrant.d/boxes
主機系統上的目錄。舊版本的盒子將繼續在同一位置可用,直到您從緩存文件夾中手動刪除 Vagrant 盒子。
您可以通過列出所有已安裝的 Vagrant 框來檢查它,如下所示:
$ vagrant box list
樣本輸出:
Fedora33 (libvirt, 0)
archlinux/archlinux (virtualbox, 20201201.10292)
archlinux/archlinux (virtualbox, 20201215.11392)
fedora33 (virtualbox, 0)
generic/alpine38 (virtualbox, 3.1.16)
oraclelinux/7 (virtualbox, 7.9.184)
oraclelinux/8 (libvirt, 8.3.183)
正如您在上面的輸出中看到的,Arch Linux vagrant box 有兩個版本。您不必保留兩個相同操作系統的盒子。現在讓我們刪除舊的 Vagrant 框。
刪除過時的 VagrantBox
你可以使用它 vagrant box prune
從 Linux 系統中刪除過時的 Vagrant 盒子的命令。
首先,我們來看看哪些box被刪除,哪些box被保留 --dry-run
選項。這個選項是 模擬命令 Linux 系統上不需要更改。
$ vagrant box prune --dry-run
這個命令實際上並沒有刪除框,它只是打印要刪除的框。
樣本輸出:
The following boxes will be kept...
Fedora33 (libvirt, 0)
archlinux/archlinux (virtualbox, 20201215.11392)
fedora33 (virtualbox, 0)
generic/alpine38 (virtualbox, 3.1.16)
oraclelinux/7 (virtualbox, 7.9.184)
oraclelinux/8 (libvirt, 8.3.183)
Checking for older boxes...
Would remove archlinux/archlinux virtualbox 20201201.10292
正如您在上面的輸出中看到的,archlinux/archlinux virtualbox 20201201.10292
將從系統中刪除。
現在您知道要刪除哪個框了。如果您願意,請執行相同的命令而不執行該命令。 --dry-run
選項:
$ vagrant box prune
此命令保留當前更新的框並刪除所有其他過時的框。
The following boxes will be kept...
Fedora33 (libvirt, 0)
archlinux/archlinux (virtualbox, 20201215.11392)
fedora33 (virtualbox, 0)
generic/alpine38 (virtualbox, 3.1.16)
oraclelinux/7 (virtualbox, 7.9.184)
oraclelinux/8 (libvirt, 8.3.183)
Checking for older boxes...
Removing box 'archlinux/archlinux' (v20201201.10292) with provider 'virtualbox'...
Vagrant-libvirt plugin removed box only from you LOCAL ~/.vagrant/boxes directory
From libvirt storage pool you have to delete image manually(virsh, virt-manager or by any other tool)

然後檢查已安裝盒子的列表。
$ vagrant box list
Fedora33 (libvirt, 0)
archlinux/archlinux (virtualbox, 20201215.11392)
fedora33 (virtualbox, 0)
generic/alpine38 (virtualbox, 3.1.16)
oraclelinux/7 (virtualbox, 7.9.184)
oraclelinux/8 (libvirt, 8.3.183)

看?現在,您將看到 archlinux vagrant 框。過時的盒子將被刪除。
這個 prune
該命令還有其他有用的選項。你可以使用它 -p
, --provider
使用特定提供程序(例如 Virtualbox 或 libvirt)銷毀盒子的選項。
這個 -f
, --force
即使您正在使用該盒子,徽標也會被丟棄而無需確認。這個 -k
, --keep-active-boxes
選擇讓盒子繼續使用。
要顯示幫助部分,請運行以下命令:
$ vagrant box prune --help
Box VersioningDelete vagrant boxLinuxVagrantVagrant box虛擬化