Open In App

How to set the environmental variable LD_LIBRARY_PATH in Linux

Last Updated : 09 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

There are various ways of setting a path for an environment variable. This path can be very useful when we use it later. These paths allow us to use the variable in a particular window or terminal in a particular manner. The LD_LIBRARY_PATH is an environment variable that helps the user to set a path for shared libraries which can be made available during the execution. Below are the steps to set this variable on your system.

The Linux distribution that will be used in this article is Ubuntu, you can use any distro of your choice.

Step 1: Open the bashrc file with a file editor:

The file in which we will add a path will be the bashrc file. Use the below command to open the file. The editor that is used in this article is nano, you can use any editor of your choice(like vi, vim, etc).

nano  ~/.bashrc

 

The bashrc file

Step 2: Edit the file:

After opening the file add the below command in the file.

export LD_LIBRARY_PATH = <the_custom_path_to_your_library>

For the sake of this article we will be using a sample path -> /home/osboxes/mukul.

export LD_LIBRARY_PATH = /home/osboxes/mukul

 

Save the file and exit the editor.

Step 3: Sourcing the profile

After editing the file, use the below command to source the profile.

source  ~/.bashrc

 

Step 4: Verify that the path has been added:

To see if the path has been added or not use the below command. If you are not seeing the path that we added then follow the above steps properly.

echo  $LD_LIBRARY_PATH

The path can be seen clearly.

Step 5: Appending a path to the library path:

Usually, the library path is not changed again, because doing so can break other libraries and dependencies. To avoid that, we can append another path to the Library path. For the sake of this article, we have created a folder named sample. The path to sample(/home/osboxes/sample) will be appended to the library path.  Use the below command to append

export LD_LIBRARY_PATH= $/home/osboxes/sample/ : ${LD_LIBRARY_PATH}

 

Save the file and exit. Do not forget to source the profile or else the changes will not be reflected.

source  ~/.bashrc

Verify the path by typing:

 echo  $LD_LIBRARY_PATH

The path is appended successfully.

This was how you can set the environmental variable LD_LIBRARY_PATH in Linux. 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads