I want to automatically add a new path to the $PATH variable each time when my RPM package is installed.

I tried to use a post installation script in the my RPM. Here is the part of RPM spec file containing this post installation script:

export PATH

But after successful installation the $PATH doesn't changed. Please help me with that issue.


You can't change the user's environment like that. You could try adding something to /etc/profile, but that's a disaster. You could put a file in /etc/profile.d, which is better, but your distro might not support it. The best solution would be to put a symlink from a place that's already in your path, e.g.:

ln -s /weird/place/my-program /usr/bin/my-program

All you did was to set the variable for the duration of the post-installation script. That doesn't affect the path anywhere else.

The system path is set from many locations, some of them dependent on the distribution. The one way that exists everywhere is /etc/profile. But a package installation script is not allowed to modify /etc/profile by any sane distribution's rules.

The real answer to your question is: don't do this. If an executable belongs in the path, and is provided by a package, then the executable belongs in /usr/bin. You don't have to put the executable itself there: it's the usual way, but it's ok to put a symbolic link. For example, if all of your program's executables are in /usr/lib/myprogram/bin, then link the ones that should be in the path in /usr/bin. Include the symbolic links in the rpm, so that they will be properly tracked by the package manager (do not create them in the postinstall script). You can create them in the %install section of the RPM spec, which is executed when the RPM is built (see also Creating symlink in /usr/bin when creating an RPM):

ln -s ../../lib/myprogram/foo ../../lib/myprogram/bar ${RPM_BUILD_ROOT}%{_bindir}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.