-1

I'm sorry for the uninformative question title, if you come up with a better one, feel free to edit.

So, I made the mistake of installing Python 3.9.2 using these instructions on DigitalOcean. However, this has overridden my python3 shortcut, which now refers to 3.9.2. What do I do to

  1. uninstall this python version?
  2. bring things back to normal?

P.S. Is there even a good way to install a specific version of Python like 3.9.2? An alternative to what's in the tutorial? The method described here works if I just put in 3.9, which I suppose isn't as specific.

terdon
  • 100,812
  • 1
    I guess, just deleting the link /usr/bin/python3.9 and the directory /opt/Python-3.9.2 should be enough. – FedKad Mar 07 '24 at 10:13
  • 1
    Not sure if that's even needed, @FedKad. Can't the OP just use update-alternatives to make python3 point to the desired version? Not posting an answer because I haven't used a Debian system in a few years and I don't remember the details off the top of my head. – terdon Mar 07 '24 at 10:43

1 Answers1

1

By default, any well-behaved source code package will install itself in /usr/local instead of touching anything else in /usr. This is because /usr/local is meant for local additions by the system administrator, to avoid changing and conflicting with files installed by the package manager (in this case apt).

You should never modify and create files anywhere else in /usr. There's a lot of bad advice online, including the tutorial you've followed. In almost every case there's an equivalent to a /usr directory in /usr/local that will complement (and override) the other. For example, /usr/local/bin complements /usr/bin.

Now with this knowledge, how do we remove manually installed software from /usr/local? It depends.

In general, it's safe to remove the directory as a whole, if you know that you don't want to keep anything you installed this way. apt never installs things here, so this should not break anything, though it is wise to back it up.

If there's things you want to keep, you will need to inspect the directories yourself, and play the role of package manager, looking for files belonging to the program. Usually it's not hard to figure out as they will be named accordingly. For example, to delete all manually installed versions of python3, you could accomplish it with the following commands:

rm -r /usr/local/bin/python3*
rm -r /usr/local/lib/python3*
rm -r /usr/local/lib/libpython3*

Additionally, the instructions overwrote the symlink in /usr/bin/python3.9. It's wise to reinstall python using apt instead of removing that file - if it's required it will be updated by the package manager.

mid_kid
  • 691