3

I am working on a legacy cross-platform project packaged to both DEB and RPM formats.

Once the Linux package is installed, an environment variable holding the path to the installation folder is required for scripts (e.g. CMake and Bash scripts) and programs execution. This variable has a known name and can point to Program Files\My Package on Windows and to /opt/my_package on Unix systems.

Currently, Linux users have to manually register the variable to use the software. A convenient solution would be to register the environment variable as part of the package installation.

I am aware one can set system-wide environment variables in configuration files such as /etc/profile and /etc/bashrc. I could modify such a file as part of the postinst script.

Is it a good practice to create system-wide environment variables during package installation? If so, what is the preferred way to do it?

The Linux packages are distributed to users on Ubuntu 16.04 and RHEL 7.

sgc
  • 33
  • Related: https://unix.stackexchange.com/q/348295/117549 and https://unix.stackexchange.com/q/64258/117549 and https://unix.stackexchange.com/a/117470/117549 – Jeff Schaller Dec 22 '18 at 01:16

1 Answers1

3

I believe both Ubuntu and RHEL use an /etc/profile.d/ structure, and I would recommend that you package a file in that directory, perhaps named for your application; e.g. /etc/profile.d/legacyapp.sh (and /etc/profile.d/legacyapp.csh if you need to support the CSH family).

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255