The “LD_LIBRARY_PATH” is an environmental variable that displays the shared libraries’ search paths. The “shared libraries” manage the Linux system dependencies that are loaded before an application starts. They load only once in the system before startup and save memory usage by a software application.
The “LD_LIBRARY_PATH” is used to compare the older and the updated versions of any application and keep reviving the older versions of the applications. It also assists the users in creating a new system in which libraries can be changed independently.
This post lists the “LD_LIBRARY_PATH” objective and the complete procedure to set it in Linux.
- Objective of LD_LIBRARY_PATH
- Set the “LD_LIBRARY_PATH” Environment Variable
What is the Objective of LD_LIBRARY_PATH?
The main objective of the “LD_LIBRARY_PATH” in Linux is that it tells the Dynamic Link Loader from where to search the files linked with the specified application. The “Dynamic Link Loader” loads and links the shared libraries at the execution time.
The “LD_LIBRARY_PATH” also saves processing time by telling it from where the files should be searched.
How to Set the “LD_LIBRARY_PATH” Environment Variable?
The following essential steps are required to set the “LD_LIBRARY_PATH” environment variable.
Step 1: Access the “.bashrc” File
First, open up the “~/.bashrc” file in the default text editor “nano”. The “BASH shell script ” also sets the environment variables in an interactive “bash” shell at the start of the shell session.
$ nano ~/.bashrc
Step 2: Set the LD_LIBRARY_PATH
Scroll down the file and add the following line into it:
export LD_LIBRARY_PATH=/home/Sample/New
The “export” command sets the “LD_LIBRARY_PATH” environment variable path that is “/home/Sample/New”:
Press “Ctrl+S” to save and “Ctrl+X” to exit the editor.
Step 3: Update the “bashrc” File
Update the “bashrc” file when all the changes have been done using the below-mentioned command:
$ source ~/.bashrc
Step 4: Check the LD_LIBRARY_PATH
Check the new path of the “LD_LIBRARY_PATH” environment variable using the “echo” command:
$ echo $LD_LIBRARY_PATH
The new path “home/Sample/New” path has been set.
Conclusion
In Linux, the “LD_LIBRARY_PATH” corresponds to an environment variable to search the directories of the shared libraries. The user can also set it using the “export” command to specify the particular path where the shared libraries will be stored.
This post has described the objective and the complete procedure to set the “LD_LIBRARY_PATH” environment variable.