当 Firefox 需要 snap 但 snap 不起作用时,如何在 WSL 中安装 Firefox?

Lig*_*k05 10 apt firefox software-installation snap windows-subsystem-for-linux

所以我想在 Ubuntu 的 WSL2 中安装 Firefox。现在,使用

sudo apt install firefox
Run Code Online (Sandbox Code Playgroud)

给我这个输出:

Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  firefox
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 72.3 kB of archives.
After this operation, 261 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 firefox amd64 1:1snap1-0ubuntu2 [72.3 kB]
Fetched 72.3 kB in 0s (420 kB/s)
Preconfiguring packages ...
Selecting previously unselected package firefox.
(Reading database ... 24109 files and directories currently installed.)
Preparing to unpack .../firefox_1%3a1snap1-0ubuntu2_amd64.deb ...
=> Installing the firefox snap
==> Checking connectivity with the snap store
===> System doesn't have a working snapd, skipping
Unpacking firefox (1:1snap1-0ubuntu2) ...
Setting up firefox (1:1snap1-0ubuntu2) ...
update-alternatives: using /usr/bin/firefox to provide /usr/bin/gnome-www-browser (gnome-www-browser) in auto mode
update-alternatives: using /usr/bin/firefox to provide /usr/bin/x-www-browser (x-www-browser) in auto mode
Run Code Online (Sandbox Code Playgroud)

此时尝试启动 Firefox 将失败:


Command '/usr/bin/firefox' requires the firefox snap to be installed.
Please install it with:

snap install firefox
Run Code Online (Sandbox Code Playgroud)

一旦我运行所说的 snap 命令,我得到这个:

error: cannot communicate with server: Post "http://localhost/v2/snaps/firefox": dial unix /run/snapd.socket: connect: no such file or directory
Run Code Online (Sandbox Code Playgroud)

谁能帮我这个?我不是 Linux 专家。

Han*_*nnu 17

快速回答:

使用浏览器并查看:
https://ubuntuhandbook.org/index.php/2022/04/install-firefox-deb-ubuntu-22-04/

简而言之 (如果您已经这样做了,您可能需要跳过前两个)

sudo snap remove firefox
sudo apt remove firefox
sudo add-apt-repository ppa:mozillateam/ppa

# Create a new file, it should be empty as it opens:
sudo gedit /etc/apt/preferences.d/mozillateamppa

# Insert these lines, then save and exit
Package: firefox*
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 501

# after saving, do
sudo apt update
sudo apt install firefox # or firefox-esr
Run Code Online (Sandbox Code Playgroud)


Not*_*1ds 9

System doesn't have a working snapd, skipping

看来您可以:

  • 使用较旧的 WSL2 版本
  • 或者尚未在 WSL2 上启用 Systemd

现在,通过启用 Systemd 功能,WSL2 上的 Ubuntu 支持 Snap,如我在此处的回答中所述。

但是,请考虑您是否真的需要这个:

  • 正如我在回答中提到的,启用 Systemd 会产生并不总是需要的额外开销。
  • Windows 版本的 Firefox 可能是更好的选择(除非您确实需要测试某些特定于 Ubuntu 或 Linux 的 Firefox 功能)。
  • 其他答案中提到的 PPA 也是一个有效的替代方案。