Certbot not found when installed with snap and using Fish

I learned that my certbot version (0.40) is very old. So I set out to update it:

  • I made sure that I was running the latest edition of my Linux flavour
    cat /etc/issue
    Ubuntu 20.04.1 LTS \n \l

  • I made sure that my package lists were up-to-date:
    apt update
    […snip…]
    All packages are up to date.

  • I made sure my certbot copy is at the latest version:
    apt upgrade certbot
    […snip…]
    certbot is already the newest version (0.40.0-1).
    Calculating upgrade... Done
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

  • To refresh my memory how to properly install certbot on my flavor of Linux with my flavor of web server, I revisited this site:
    https://certbot.eff.org/lets-encrypt/ubuntufocal-nginx

  • It produced this outcome:
    I learned that instead of a PPA they now instruct to use Snap

  • I ran this command to get rid of the official Ubuntu certbot version (0.40.0):
    apt remove certbot

  • As per instructions, I ran these commands to install Certbot:
    sudo snap install --classic certbot

  • It produced this output:
    Command 'snap' not found, but can be installed with:
    apt install snapd

  • I concluded that my provider (Hetzner) has modified the default Ubuntu 20.04 instance because I read that Snap should be installed by default. I did not really want 120MB more SSD space to be wasted on my tiny VPS, so I tried to switch to PPA instead:

  • I ran this command:
    sudo add-apt-repository ppa:certbot/certbot

  • It produced this output:
    Err:10 http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release
    404 Not Found [IP: 2001:67c:1560:8008::15 80]
    E: The repository 'http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release' does not have a Release file.
    N: Updating from such a repository can't be done securely, and is therefore disabled by default.
    N: See apt-secure(8) manpage for repository creation and user configuration details.

  • I googled what’s going on and learned that due to lack of experience with packaging by the certbot team, PPA has been abandoned in favor of the snap system.

  • So I ran this command to remove the PPA:
    sudo add-apt-repository -r ppa:certbot/certbot

  • And installed snap by running this command:
    apt install snapd

  • It produced this output:
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following additional packages will be installed:
    squashfs-tools
    Suggested packages:
    zenity | kdialog
    The following NEW packages will be installed:
    snapd squashfs-tools
    0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
    Need to get 27.4 MB of archives.
    After this operation, 120 MB of additional disk space will be used.
    Do you want to continue? [Y/n]
    Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 squashfs-tools amd64 1:4.4-1 [121 kB]
    Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 snapd amd64 2.45.1+20.04.2 [27.3 MB]
    Fetched 27.4 MB in 1s (34.2 MB/s)
    sh: 0: getcwd() failed: No such file or directory
    sh: 0: getcwd() failed: No such file or directory
    sh: 0: getcwd() failed: No such file or directory
    Selecting previously unselected package squashfs-tools.
    (Reading database ... 43539 files and directories currently installed.)
    Preparing to unpack .../squashfs-tools_1%3a4.4-1_amd64.deb ...
    Unpacking squashfs-tools (1:4.4-1) ...
    Selecting previously unselected package snapd.
    Preparing to unpack .../snapd_2.45.1+20.04.2_amd64.deb ...
    Unpacking snapd (2.45.1+20.04.2) ...
    Setting up squashfs-tools (1:4.4-1) ...
    Setting up snapd (2.45.1+20.04.2) ...
    Created symlink /etc/systemd/system/multi-user.target.wants/snapd.apparmor.service → /lib/systemd/system/snapd.apparmor.service.
    Created symlink /etc/systemd/system/multi-user.target.wants/snapd.autoimport.service → /lib/systemd/system/snapd.autoimport.service.
    Created symlink /etc/systemd/system/multi-user.target.wants/snapd.core-fixup.service → /lib/systemd/system/snapd.core-fixup.service.
    Created symlink /etc/systemd/system/multi-user.target.wants/snapd.recovery-chooser-trigger.service → /lib/systemd/system/snapd.recovery-chooser-trigger.service.
    Created symlink /etc/systemd/system/multi-user.target.wants/snapd.seeded.service → /lib/systemd/system/snapd.seeded.service.
    Created symlink /etc/systemd/system/cloud-final.service.wants/snapd.seeded.service → /lib/systemd/system/snapd.seeded.service.
    Created symlink /etc/systemd/system/multi-user.target.wants/snapd.service → /lib/systemd/system/snapd.service.
    Created symlink /etc/systemd/system/timers.target.wants/snapd.snap-repair.timer → /lib/systemd/system/snapd.snap-repair.timer.
    Created symlink /etc/systemd/system/sockets.target.wants/snapd.socket → /lib/systemd/system/snapd.socket.
    Created symlink /etc/systemd/system/final.target.wants/snapd.system-shutdown.service → /lib/systemd/system/snapd.system-shutdown.service.
    snapd.failure.service is a disabled or a static unit, not starting it.
    snapd.snap-repair.service is a disabled or a static unit, not starting it.
    Processing triggers for man-db (2.9.1-1) ...
    Processing triggers for mime-support (3.64ubuntu1) ...

  • I installed Certbot as per instructions:
    sudo snap install --classic certbot

  • It produced this output:
    2020-08-29T23:39:11+03:00 INFO Waiting for automatic snapd restart...
    certbot 1.7.0 from Certbot Project (certbot-eff✓) installed

  • I attempted to run certbot:
    certbot

  • It produced this output:
    Command 'certbot' is available in '/snap/bin/certbot'
    The command could not be located because '/snap/bin' is not included in the PATH environment variable.
    certbot: command not found

  • I attempted to find certbot with the find command:
    find / -name certbot -type f -executable
    /snap/certbot/500/bin/certbot

  • I attempted to run the found file:
    /snap/certbot/500/bin/certbot
    Traceback (most recent call last):
    File "/snap/certbot/500/bin/certbot", line 5, in <module>
    from certbot.main import main
    ModuleNotFoundError: No module named 'certbot'

  • I got stuck and wrote this post and redid everything to document my steps.

  • When I reached the last step, I spotted this The command could not be located because '/snap/bin' is not included in the PATH environment variable. part which I missed last time.

  • I attempted to run certbot again:
    /snap/bin/certbot

  • It worked.

  • I realized that I am using Fish.

  • I added /snap/bin to Fish paths by running:
    set -ga fish_user_paths /snap/bin

Just posting to let you guys realize what I was going through “thanks” to the fact that Certbot had moved from PPA to Snap and to help others using Fish, too.

2 Likes

This looks a little bit like the requirement for hash -r in bash shells when one used to use the certbot package and moved to the snap in the same shell environment.

1 Like

I didn’t know about the bash’s built-in command hash before and had to look it up. Basically bash memorizes the commands found in PATH not to consult the contents of the directories in PATH every time but sometimes this memory, or cache rather, becomes invalid and you must tell Bash to forget the cache by running hash -r. I couldn’t find anything similar in Fish.

I think that the culprit in my case was the fact that the snap installation procedure has not been tested with Fish and because of that /snap/bin does not get added to the PATH automatically and that’s why the things installed with snap don’t work for Fish users unless they manually add /snap/bin to PATH themselves.

1 Like

@bmw Have you tested the certbot snap on Fish? Looks like a possible issue here.

1 Like

Didn’t it get added in /etc/profile.d/apps-bin-path.sh?

I think fish should still read that.

Maybe the instructions need something to reload /etc/profile. The snapd installations instructions cover this in a pretty vague way:

Either log out and back in again, or restart your system, to ensure snap’s paths are updated correctly.

1 Like

Ugh… Anything or anyone which/who recommends an *nix system to be restarted – with the exception of kernel updates – should not be trusted IMHO…

1 Like

Snap indeed creates shell scripts in /etc/profile.d but Fish doesn’t read them.

It’s using these directories for reading additional configuration:

  • /usr/share/fish/conf.d for packages

  • /etc/fish/conf.d for administrators ($__fish_sysconfdir/conf.d)

  • ~/.config/fish/conf.d for users ($XDG_CONFIG_HOME/fish/conf.d)

It reads files that end in .fish but for each name only the one in the highest-precedence directory.

Snapd should make a .fish file in one of the conf.d directories for fish and a /etc/profile.d script for other shells.

Since it doesn’t and since the possibility to stumble over similar issues is high, the best way to avoid this and similar problems in the future is to set the default shell back to bash and add fish as a command to be launched from bashrc or whereever when bash launches. That way the Bash environment state, along with PATH, will be passed to Fish.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.