Snap doesn't work at all after I followed some instructions

Welcome to Linux, one of the really nice things with Linux that got me hooked back in the day was that is was so easy to change things. This of course also means it’s easy to break things. What I have learned it to never run any commands that I do not understand. That will make it much easier to understand whats going on and how to solve potential problems. This has of course also the added bonus of learning something new.

sudo mv /var /var.BAK
sudo mkdir /var

This will move (mv) the directory /var to /var.BAK and make a directory (mkdir) called /var, or in simple English: Rename var to var.BAK and make an empty var.

Linux is inspired from older UNIX-systems and have adopted the same directory layout, if you are curious you can read more about it here. “var” stands for “Variable files”, a place to store data that changes. This directory is used by a plenty of different applications (not only snapd) so by emptying /var you may have broken several applications.

Good thing, you have an backup in var.BAK, so it should be simple to restore. I assume you changed nothing else, and then executed the commands suggested by @ijohnson the backup (/var.BAK) was not properly restored. Instead of overwriting the empty /var, you moved var.BAK inside /var.

I would first look inside /var to make sure that the current state is what I think it is. For that use the list command (ls):

ls /var

That should list all non-hidden files inside the directory. On my system it looks like this:

$ ls /var
backups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  snap  spool  tmp

I suspect that you only see your var.BAK directory there, or possible some other files that the system has re-created. If this is true, do this:

Move the backup directory back to it’s original position

sudo mv /var/var.BAK /

If /var contained additional files, save them (just in case you need them):

sudo mv /var /var.BAK2

or if var did not contain additional files, just remove the empty directory with “remove dir” (rmdir):

sudo rmdir /var

Now, run the commands suggested by @ijohnson:

sudo mv /var.BAK /var

This time, /var does not exists so the directory will be renamed from var.BAK to var.

Reboot the system, and try out the snap commands and see what happens:

sudo reboot
1 Like