How to uninstall the currently installed version and then install a targeted version?

Did you mean to use which -a swipl which is different?

The things that I don’t know for certain that might cause a problem:

  1. Are links being used in either the old or the new install?

  2. Are the necessary files of the old install in a single directory?

I am quite familiar with installing SWI-Prolog as a clean install on Windows and Linux but I have never tried to uninstall a version on Linux before 7.x. After reading your question I did a fresh install using the instructions you noted on Ubuntu 20.x running on WSL on Windows.

These should help you see what and new install of SWI-Prolog on Linux should look like.

root@System:~# which swipl
/usr/bin/swipl

root@System:~# which -a swipl
/usr/bin/swipl
/bin/swipl

If I use ls -la /usr/bin/swi* this is the result

root@System:~# ls -la /usr/bin/swi*
lrwxrwxrwx 1 root root 40 Jun 22 06:12 /usr/bin/swipl -> ../lib/swi-prolog/bin/x86_64-linux/swipl
lrwxrwxrwx 1 root root 43 Jun 22 06:12 /usr/bin/swipl-ld -> ../lib/swi-prolog/bin/x86_64-linux/swipl-ld

The real location for the executable on Linux is

root@System:/usr/lib/swi-prolog/bin/x86_64-linux# ls -la
total 60
drwxr-xr-x 2 root root  4096 Jun 29 09:13 .
drwxr-xr-x 3 root root  4096 Jun 29 09:13 ..
-rwxr-xr-x 1 root root 14488 Jun 22 06:12 swipl
-rwxr-xr-x 1 root root 35160 Jun 22 06:12 swipl-ld

and this shows that the file is an executable and not a link or something else.

root@System:/usr/lib/swi-prolog/bin/x86_64-linux# file swipl
swipl: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=3ac36635b238ba8597050b718d9c5bb5d8907faa, for GNU/Linux 3.2.0, stripped

As for using dpkg when installing SWI-Prolog I have never had the need. The reason being as when I install on Linux I typically just destroy the old version of Linux as it sits on WSL and is just a set of files in a directory. So I can’t be of help with dpkg

As for the nox version, the only info I know of that might also help is in this topic,

Install SWI-Prolog development version on Ubuntu using PPA

My best guess is that you have a link somewhere in the search path that is pointing to the old version. Since you don’t need the old version, just rename it and try the swipl command again and when it fails it should give you a clue as to what to remove/change next. Just keep fixing until the swipl command works as expected and then delete all of the renamed files and unnecessary links.

At this point there is not much more help I can give. :neutral_face: