Manage 3rd Party Software in GNU/Linux using opt

Using GNU/Linux on the desktop and for software development, there are many situations where you can not use the package management of your favorite distribution. For example your desired IDE, let's say Eclipse, is outdated or your required library has some dependency conflicts. To solve these and other problems, you can install, extract or compile your software manually from the project's website. During the last months I had to do it a lot ... and I almost lose track of all files, sim links, executables, entries for start menu and so on. UNIX like operating systems reserved the /opt folder for third party software, add-on packages and so on, which are not controlled by the system. Unfortunately, it's on you to handle everything:

  • dash/start menu entries
  • accessable executables in your shell (PATH)
  • loadable shared objects
  • tracking of deleted software

I present a simple concept to manage 3rd Party Software using the /opt folder, taking account for the mentioned points above.

Note: Due to the configuration snippets and examples, this article is a litte bit long - but not complicated!

Overview

The aim is a central and clear management of additional software. We do not want to mess up the core system (/usr) with zombie files and links. But without touching the system, a usable setup is not possible - we have to modify thes files/folders:

  • /usr/share/applications/ - Shortcuts for start menu entries (*.desktop)
  • /etc/environment - Extend the search path for executables (PATH)
  • /etc/ld.so.conf.d/ - Register new folder for shared objects

That's all - keep these three spots in mind and your are happy. For /opt, I am using the following structure:

/opt/applications/   # Applications, software with user front-end, e.g. Eclipse
/opt/bin/            # Scripts, executables, symbolic links to applications/misc
/opt/include/        # Header files for development, e.g. eigen
/opt/lib/            # Libraries static/dynamic, e.g. Qt5
/opt/misc/           # Optional

Of course you can extend this structure for your use case, e.g. you want an extra folder for video games.

Setup system for opt

You need root rights or sudo for the following instructions.

  • Create folder:
mkdir /opt/applications
mkdir /opt/bin
mkdir /opt/include
mkdir /opt/lib
mkdir /opt/misc
  • Add /opt/bin to PATH:
# Modify: /etc/environment
editor /etc/environment
# Extend existing entry:
PATH=":/opt/bin"
# Save file
  • Register /opt/lib for shared objects:
# Create new file: /etc/ld.so.conf.d/opt_lib.conf
editor /etc/ld.so.conf.d/opt_lib.conf
# Add line:
/opt/lib
# Save file

Install an application

Let's install an application, e.g. Eclipse!

  • Download the latest version from http://www.eclipse.org/downloads
  • Create folder: mkdir /opt/applications/eclipse
  • Extract downloaded file to: /opt/applications/eclipse/
  • Create starter for the shell.
  • Create an entry for the start menu.

(4) Starter/executable for shell/CLI

If you want to start or access your software via shell, you have to create a symbolic link of the executable to /opt/bin:

ln -s /opt/applications/eclipse/eclipse /opt/bin/eclipse

(5) Start menu entry - the .desktop file

To start the software via the start menu of the desktop environment, we need a .desktop file:

  • Create .desktop file: touch /opt/applications/eclipse/eclipse.desktop
  • Modify eclipse.desktop:
[Desktop Entry]
Type=Application
Name=Eclipse
Comment=Eclipse Integrated Development Environment
Icon=/opt/applications/eclipse/icon.xpm
Exec=/opt/applications/eclipse/eclipse
Terminal=false
Categories=Development;IDE;Java;
  • Register Eclipse in start menu (do not copy the file!):
ln -s /opt/applications/eclipse/eclipse.desktop /usr/share/applications/eclipse.desktop
  • You may have to reboot to see the entry in the start menu.

Installing libraries and includes

/opt/include and /opt/lib can be used for software development. For example, in GCC you can use the flags -I/opt/include and -L/opt/lib. The following example is for the library and framework Qt5:

  • Qt5 folders:
/opt/misc/qt5
/opt/misc/qt5/include
/opt/misc/qt5/lib
  • SimLink for include:
ln -s /opt/misc/qt5/include /opt/include/qt5
  • SimLink for lib:
ln -s /opt/misc/qt5/lib /opt/lib/qt5

Uninstalling software

To uninstall a software, you just have to remove the related folders, e.g.:

rm -r -f /opt/applications/eclipse

For an application or similar, the executable and/or .desktop file must be removed, too:

rm -r -f /opt/bin/eclipse
rm -r -f /usr/share/applications/eclipse.desktop

For a library and the header files:

rm -r -f /opt/misc/qt5
rm -r -f /opt/include/qt5
rm -r -f /opt/lib/qt5

If you forgot to delete the related files for an additional software, you can list broken simlinks with:

find -L /opt/bin -type l
find -L /opt/include -type l
find -L /opt/lib -type l
find -L /usr/share/applications -type l

That's it!

Hint: non-root solution

If you do not have root access to your machine, e.g. your PC at school, university or work, the presented concept can be adopted to the home folder. You just need these modifications:

  • Move opt to home:
/home/user/opt/...
# instead of /opt
  • .desktop files:
~/.local/share/application
# instead of /usr/share/applications
  • Extend PATH:
# Modify: ~/.pam_environment
editor ~/.pam_environment
# Add line:
PATH DEFAULT=${PATH}:/home/user/opt/bin
# instead of /etc/environment
  • Shared libraries:
# execute in your open shell
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/opt/lib
# instead of /etc/ld.so.d/opt_lib.conf

Links:

By @Christof Pieloth in
Tags : #opt, #linux, #ubuntu, #howto, #Best Practice, #installation, #configuration,