How to change RPATH or RUNPATH of executable

RPATH or RUNPATH is a colon-separated list of directories embedded in an executable. This list of directories play an important role when shared library file locations are determined at the time when the executable is loaded for running. This process is described in this post. Note that RPATH has highest priority in the shared library search, compared to RUNPATH. We can change RPATH or RUNPATH of a binary file by using the chrpath tool.

  • Installing this tool is easy:
$ sudo apt install chrpath
  • To view if the binary has RPATH or RUNPATH and to list its colon-separated list of directories:
$ chrpath ./some_binary
  • To remove RPATH or RUNPATH from the binary:
$ chrpath -d ./some_binary
  • To convert RPATH of a binary to a RUNPATH:
$ chrpath -c ./some_binary

Note that you cannot convert a RUNPATH back to RPATH.

  • To replace RPATH or RUNPATH paths with a different set of paths:
$ chrpath -r /home/joe:/home/foobar/lib64 ./some_binary

Note that the string of the new set of paths should be smaller or equal to the length of what was stored earlier in the binary.

Tried with: chrpath 0.14 and Ubuntu 16.04

One thought on “How to change RPATH or RUNPATH of executable

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.