Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

%post
PATH=$PATH:/usr/app/mdg/bin
export PATH

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

share|improve this question
add comment

2 Answers 2

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
share|improve this answer
add comment

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):

%install
…
ln -s ../../lib/myprogram/foo ../../lib/myprogram/bar ${RPM_BUILD_ROOT}%{_bindir}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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