Link to home
Start Free TrialLog in
Avatar of Dima Iva
Dima Iva

asked on

How to get rid of Snap in Ubuntu?

Being new to Ubuntu (my version is 20.04), I got a couple of software programs installed using the "Software" program.  Then I noticed that in the file system it places them into a /snap/ directory.  Then I read about snap and decided that I don't want to use it, but rather to install software from command line using apt.   It looks like even after clicking "uninstall" for postgresql10l, for example, the snap directory is still there. Now, I wonder how to get rid of "snap" and the directories it created completely, as well as of these /dev/loop directories?

Avatar of David Favor
David Favor
Flag of United States of America image

Deinstalling snap is easy.

apt-get -y purge snap snapd

Open in new window


And this can destroy essential services.

For example, looking at of my random Ubuntu Focal machines I see...

net17 # snap list
Name     Version   Rev    Tracking         Publisher     Notes
certbot  1.20.0    1514   latest/stable    certbot-eff✓  classic
core18   20210722  2128   latest/stable    canonical✓    base
core20   20210928  1169   latest/stable    canonical✓    base
googler  4.3.2     736    latest/stable    snapcrafters  -
lxd      4.19      21723  latest/stable/…  canonical✓    -
nmap     7.92      2536   latest/stable    maxiberta     -
snapd    2.52.1    13640  latest/stable    canonical✓    snapd

Open in new window


So if I destroy snap then...

1) All my LXD containers instantly go offline or worse (and more likely) they go offline next time logrotate runs or a reboot occurs.

2) Since certbot is a snap package, no more TLS certs can be generated or renewed, which means as certs expire sites die... randomly over a 90 day window.

3) No more port scans as nmap dies...

If your new to Ubuntu... touch snap at your own peril...
You can provide the output of the following for review, to guess at what will go offline if you nuke snap...

snap list

Open in new window

Avatar of Dima Iva
Dima Iva

ASKER

That sounds scary, David.  What I have is:

dspace@device$ snap list
Name                 Version    Rev    Tracking       Publisher   Notes
canonical-livepatch  9.8.0      114    latest/stable  canonical✓  -
core                 16-2.52.1  11993  latest/stable  canonical✓  core
core18               20210722   2128   latest/stable  canonical✓  base
core20               20210928   1169   latest/stable  canonical✓  base
lxd                  4.0.7      21545  4.0/stable/…   canonical✓  -
snapd                2.52.1     13640  latest/stable  canonical✓  snapd

So, in my scenario, I would run into the problem with lxd containers?  Should I then leave snap as is, but use apt from command line next time I need to install something?  If so, could you tell me how to get rid of the snap version of postgresql10, since I already have postgresql12 installed?  Just delete the directory?
So, in my scenario, I would run into the problem with lxd containers?

if that was installed with snap (as your output shows) then yes, that will break it
watched a video earlier this week around ubuntu 21.10 where firefox is installed with snap
i fired it up and removed snap (i don't care for it either) and firefox went away; then you can install with apt
if you want to move to a non-snap version, would need to backup and restore your database(s) then remove snap and reinstall postgresql and restore your database(s)

Should I then leave snap as is, but use apt from command line next time I need to install something?

that's what i would do if trying to move things is too much of a hassle
going forward on a new install, you can remove snap after installation and go from there with apt
I/M/O the problem with ubuntu is that they come out with a new release every six months.  That's fine, that's great, it's always up to the minute.  I don't want to upgrade that often, but you pays your money and you takes your choice.

But:   Unless you use ubuntu as supplied out-of-the-box with the out-of-the-box tools, every six months you have to apply the same set of customizations to the new system that were applied to the old system - and hope that they still work.  So doing any significant customization to ubuntu, e.g. (a) using SysV init or (b) apt instead of snap or (c) using xtables geoIP filtering, is going to bite you hard and repeatedly at every new release.

If stability is an issue, use Debian instead.
If you use the "LTS" (Long Time Support) version of Ubuntu, you don't have to upgrade every 6 months. Those versions are supported for 5 Years as far as I know, & then you can usually upgrade to the current LTS version pretty easily so long you haven't setup something special.

Although I don't use "Snaps" currently, it is still installed on my Debian systems, as it does have it's merits. Advantages are that you don't have to make sure all dependencies are installed & the correct version, they are already included with the "Snaps". Dependencies can conflict with others so sometimes a software can't be installed without breaking something else. They also work between different Distro's without needing special compiling. A further advantage is that sometimes you can get software to work that is no longer available for your OS version, or not yet available. So I don't think you should remove snap.

I don't know the Ubuntu Software Center, but probably when you select something to install, it shows you whether it is a snap or from the normal repos, & probably, if it is available both on snap & repo, it should be listed at least twice, so you can select & install the correct version. To remove snaps, you can use the snap from the terminal. For example "snap help --all" gives you a list  of the commands you can use in snap. You could also install the snapcraft-gui tool (sudo apt install snapcraft-gui) to get a gui to manage your snaps. You could also install the synaptic package manager (sudo apt install synaptic), which is a GUI "Software Center" for apt alone, it doesn't show you snap software. So if you want to be sure what you are installing comes from the repos, use synaptic rather than the Ubuntu Software Center.
1) You said, "So, in my scenario, I would run into the problem with lxd containers?"

Since your "scenario" is unclear, as you've provided no output of "snap list", no way to say for sure.

You'll have to figure this out yourself.

And, you're correct, LXD is only getting updates through SNAP now, so... with Focal... I think you can still install a very old version of LXD through APT + it will likely be broken in various ways + if you open an LXD ticket, the first step they have you take is to delete APT LXD + install SNAP LXD.

As for PostgreSQL (which I don't run), as best I recall last time I looked at this project, you'll get fastest upgrades to latest stable using SNAP.

With APT, you can install + you'll miss most PostgreSQL updates, till next major Ubuntu version release, as I recall looking for a latest stable PPA for PostgreSQL + was unable to find one.

Might be someone who uses PostgreSQL can comment on differences of SNAP vs. APT for PostgreSQL.

2) Should I then leave snap as is...

If you'd like your system to run problem free + "snap list" shows any installed software, then the answer is yes.

3) but use apt from command line next time I need to install something?

This question depends on package involved.

For example, if you install nmap through APT, you get roughly 1-2 year old code.

If you install nmap through SNAP, you get latest stable version from the nmap project + all current patches.

4) If so, could you tell me how to get rid of the snap version of postgresql10, since I already have postgresql12 installed?  Just delete the directory?

If I ended up with multiple versions of PostgreSQL installed... first off this is a travesty + likely will lead to many problems.

I'd personally delete all PostgreSQL packages - SNAP + APT (with purge option) - so all code + data are gone.

Making a backup of any data required to survive.

Then install exactly 1x version of PostgreSQL, never multiple versions, then if I had data, restore the data into a fresh install.
Alternative you might consider.

If you're running LXD, you might take the approach I take running 1000s of projects in LXD containers.

1) At machine level only software installed is SNAP LXD + SNAP nmap, as I use nmap sometimes to scan LXD containers.

2) Then all projects - Sites/Apps/APIs - each get their own container.

3) For container Distro, I normally run Ubuntu, which installs snapd which is required for Ubuntu containers to work well.

I'm with you, to me SNAP is as bad or worse than systemd... as both or horribly bloated...

To fix these problems I'm switching shortly to using Alpine for my container OS, as Alpine doesn't use snap or systemd.

If you wait for Alpine-3.15 to release, https://pkgs.alpinelinux.org/packages?name=postgresql&branch=edge suggests PostgreSQL-14 (latest stable version) is included in Alpine-3.15 so this might be of interest to you.
So here is my OS:
dspace@device:/etc/postgresql/12/main$ lsb_release -a 
No LSB modules are available. 
Distributor ID:   Ubuntu 
Description:   Ubuntu 20.04.3 LTS 
Release:   20.04 
Codename:   focal 

Open in new window


Here is my snap list:

dspace@device$ snap list
Name                 Version    Rev    Tracking       Publisher   Notes
canonical-livepatch  9.8.0      114    latest/stable  canonical✓  -
core                 16-2.52.1  11993  latest/stable  canonical✓  core
core18               20210722   2128   latest/stable  canonical✓  base
core20               20210928   1169   latest/stable  canonical✓  base
lxd                  4.0.7      21545  4.0/stable/…   canonical✓  -
snapd                2.52.1     13640  latest/stable  canonical✓  snapd

Open in new window


I thank all the experts who contributed their knowledge.  After reading the comments, I will not try to delete SNAP, I will just not use it much.  I am installing an institutional repository software called DSpace that uses either PostgreSQL 11.x, 12.x or 13.x (with pgcrypto installed) or Oracle 10g or later.  I will stick to PostgreSQL, which I am familiar with, but Snap comes with 10.4, which is a tad behind.  So, right now I have a brand new PostgreSQL 12 installed via apt:

dspace@device:/etc/postgresql/12/main$ psql -V 
psql (PostgreSQL) 12.8 (Ubuntu 12.8-0ubuntu0.20.04.1) 

Open in new window


and all I would like to do at this stage is delete the /snap/bin/postgresql10 leftovers that Snap didn't remove during uninstall:

dspace@device:~$ locate /bin/postgres 
/snap/bin/postgresql10.clusterdb 
/snap/bin/postgresql10.createdb 
/snap/bin/postgresql10.createuser 
/snap/bin/postgresql10.dropdb 
/snap/bin/postgresql10.dropuser 
/snap/bin/postgresql10.ecpg 
/snap/bin/postgresql10.initdb 

<etc.>

Open in new window


Here is where it seems to be hiding

dspace@device:/$ locate postgresql10 
/home/dspace/.cache/gnome-software/odrs/io.snapcraft.postgresql10-W7TagWOq55vJphD3Ek4ZUtQytGRMeQqK.json 
/home/dspace/snap/postgresql10 
/home/dspace/snap/postgresql10/current 
/var/lib/snapd/sequence/postgresql10.json 

Open in new window


Is it OK to delete /home/dspace/snap/postgresql10?
Glad you got this working.

Unsure what /home/dspace/snap/postgresql10 might be.

Likely it's okay to delete this + I'd open a ticket with the Dspace project + ask.
Aside: If you're running LXD, best run PostgreSQL + Dspace in an LXD container.

The entire point of LXD is to encapsulate dependencies like your project, so projects/containers can move easily.

If you install at the machine level, you've missed all the benefits of LXD.
ASKER CERTIFIED SOLUTION
Avatar of rindi
rindi
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
+1 for @rindi's suggestion.