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

Hi,
I have a SWI-Prolog version 6.0.2 for x86_64-linux previously
installed on my Ubuntu 18.04.4LTS.
I want to uninstall this version and install a 7.2.x version or higher, my motivation being to use PySwip to use prolog with my python program.
I installed a devel version using the instructions in Installing from PPA (Ubuntu Personal Package Archive)
I got notified that the newer version is installed. But I am not able to switch to this version as when I execute swipl --version, I still get the older version. Do I need to change any environment variables? If I need to add to the PATH variable, what path should I add?

What does which swipl return?

which man page

That should give you an idea of where to look.

Dear @EricGT ,
Thank you for your suggestion.
which swipl returns /usr/local/bin/swipl as does which swipl --all

I then executed dpkg -S $(which swipl) and got dpkg-query: no path found matching pattern /usr/local/bin/swipl.
I was hoping to find the package name so that I could execute dpkg -L <packagename> to find the files and search for similar files in other directories.
Without much clarity, I also tried dpkg -L swi-prolog-nox as I saw this package name mentioned in another topic of this discourse group. But I got Package 'swi-prolog-nox' does not contain any files (!) .

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:

/usr/local suggests an old installation from source. Unless built with special options, a SWI-Prolog installation is a single directory in the lib sub tree (for Unix-like systems) with two (older 3 or four) symbolic links for the executables from the bin directory. So, do

 which swipl

to find the executable (was once called just pl), then

ls -l $(which swipl)

to see where it points to. That should be something like /usr/local/lib/swipl/bin/x86_64-linux/swipl. This means the install dir is /usr/local/lib/swipl, so simply run

rm -r /usr/local/lib/swipl

and remove the dead links from /usr/local/bin.

Note that the details may vary. The main dir can be called swipl-x.y.z if the version is included, the base name can be pl or swi-prolog, etc. This depends on the version and how it was configured originally.

I do my build with these options (I have $HOME/.local/bin in my $PATH):

cmake -DCMAKE_INSTALL_PREFIX=$HOME/.local -G Ninja ..
ninja
ctest -j5
ninja install

I can delete the installed files by

rm $(cat $HOME/src/swipl-devel/build/install_manifest.txt)

That install_manifest.txt file can give you a good idea of what to delete from your /usr/local.

1 Like

Dear @EricGT ,
Thank you for your reply. And thank you for pointing out my mistake in the command which swipl -all. I tried which -a swipl and got the second file which is of the version that I want. I then changed the PATH to prioritize this file.
Apologies for the trouble and thank you again for such detailed information and steps. :slight_smile:

Dear @jan and @peter.ludemann ,
Thank you for the information. I tried Jan’s steps to remove the older version. I will now look into Peter’s suggestions next. :slight_smile:

It was no trouble at all. :slightly_smiling_face:

I learned a few things from the post by Jan and Peter.

I wonder what went wrong? Peter’s trick works with recent versions that have been build using CMake (and provided you did not remote the build directory). 6.0.2 surely was not :slight_smile:

Dear @Jan,
Your steps worked and I was able to remove the older version. I just wanted to learn more, so wanted to try Peter’s suggestion as well. :slight_smile:

1 Like