3

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.

3 Answers 3

3

When you're adding the path in the RPM's post-script, it is only being set for the duration of the installation shell.

Within your RPM, you want to install a custom.sh file under /etc/profile.d/.

# cat /etc/profile.d/custom.sh
#!/bin/bash

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

If you're using CSH, the file should be named custom.csh.

2

Just add a soft link to the bin path instead of changing an environment variable:

%install 
# ...
ln -s /usr/app/mdg/bin/your-program /usr/bin/your-program

https://unix.stackexchange.com/questions/45540/how-to-automatically-add-new-path-to-path-variable-after-rpm-packet-installatio

0

Instead of adding the application to PATH you can create a soft link to the path already existing in the PATH. However, I would suggest creating what link in %post step - which will be executed on the target machine instead of build agent. The reason for that is you might need sudo privileges to add the link in %build or %install step. If you create the link in %post then you you will use sudo either way, but on the other host.

%define _location /usr/app/%{_name}

...

%post
ln -sf %{_location}/bin/%{_name} /usr/bin/%{_name}
# ln -sf /usr/app/mdg/bin/mdg /usr/bin/mdg

Also remember to remove the link when you remove the application from the machine:

%postun
unlink /usr/bin/%{_name}
# unlink /usr/bin/mdg

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .