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

**URL:** <https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118>\
**Category:** Installing\
**Tags:** how-to\
**Created:** [June 29, 2021, 1:01pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118 "2021-06-29T13:01:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirandhakal25](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kirandhakal25/32/3584_2.png) [@kirandhakal25](https://swi-prolog.discourse.group/u/kirandhakal25)\
**Post date:** [June 29, 2021, 1:01pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/1 "2021-06-29T13:01:57Z")

</div>

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)](https://www.swi-prolog.org/build/PPA.html)  
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?

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [June 29, 2021, 1:17pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/2 "2021-06-29T13:17:38Z")

</div>

What does `which swipl` return?

[which man page](https://linux.die.net/man/1/which)

That should give you an idea of where to look.

---

<div class="post-metadata">

**Author:** ![kirandhakal25](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kirandhakal25/32/3584_2.png) [@kirandhakal25](https://swi-prolog.discourse.group/u/kirandhakal25)\
**Post date:** [June 29, 2021, 2:01pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/3 "2021-06-29T14:01:57Z")

</div>

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 (!) `.

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [June 29, 2021, 2:27pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/4 "2021-06-29T14:27:13Z")

</div>

> [@kirandhakal25](#):
>
> which swipl --all

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](https://www.linux.com/topic/desktop/understanding-linux-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](https://docs.microsoft.com/en-us/windows/wsl/about) on Windows.

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

```bash
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

```bash
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

```bash
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.

```bash
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](https://swi-prolog.discourse.group/t/install-swi-prolog-development-version-on-ubuntu-using-ppa/2402)

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. 😐

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [June 29, 2021, 2:36pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/5 "2021-06-29T14:36:09Z")

</div>

`/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.

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [June 29, 2021, 3:27pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/6 "2021-06-29T15:27:44Z")

</div>

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

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

```

I can delete the installed files by

```prolog
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`.

---

<div class="post-metadata">

**Author:** ![kirandhakal25](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kirandhakal25/32/3584_2.png) [@kirandhakal25](https://swi-prolog.discourse.group/u/kirandhakal25)\
**Post date:** [June 29, 2021, 3:30pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/7 "2021-06-29T15:30:05Z")

</div>

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. 🙂

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. 🙂

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [June 29, 2021, 3:32pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/8 "2021-06-29T15:32:25Z")

</div>

> [@kirandhakal25](#):
>
> Apologies for the trouble

It was no trouble at all. 🙂

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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [June 29, 2021, 3:41pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/9 "2021-06-29T15:41:52Z")

</div>

> [@kirandhakal25](#):
>
> I tried Jan’s steps to remove the older version. I will now look into Peter’s suggestions next. 🙂

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 🙂

---

<div class="post-metadata">

**Author:** ![kirandhakal25](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kirandhakal25/32/3584_2.png) [@kirandhakal25](https://swi-prolog.discourse.group/u/kirandhakal25)\
**Post date:** [June 29, 2021, 3:44pm UTC](https://swi-prolog.discourse.group/t/how-to-uninstall-the-currently-installed-version-and-then-install-a-targeted-version/4118/10 "2021-06-29T15:44:38Z")

</div>

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. 🙂
