It means that “ld_library_path” contains a list of paths where these libraries are stored so that the executable files can access them whenever required.
You can also add new paths to the “ld_library_path” to maintain a well-organized system file structure. This quick guide explains a simple method to export the “ld_library_path” in Linux so that you can add new paths to it.
How to Export the Ld_Library_Path in Linux
Shared libraries are essential elements of Linux applications that consist of codes or scripts that multiple other programs can reuse. This process enhances the overall efficiency of Linux systems. When you execute a program, the system dynamically links it with the required libraries which ensures that it runs without error.
Exporting involves setting the “ld_library_path” to specific values that indicate the paths that are mentioned earlier. For this, use the “export” command in your shell’s configuration file. Go through the following sections for a step-by-step explanation:
1. Check the Current Directories in Ld_Library_Path
It is a good practice to check the current value of “ld_library_path” to check the current directories.
This command shows nothing in our system because we have yet to configure it. In general, it displays either the added path of libraries or nothing.
2. Configure the Shell
Bash is the default shell in most of the Linux distros. However, you can always change the shells according to your needs. To configure a shell, you must open your shell’s configuration file using one of the following commands that correspond to your shell:
For Bash: nano ~/.bashrc
For Zsh: nano ~/.zshrc
For Fish: nano ~/.config/fish/config.fish
Always remember that the tilde (~) sign indicates the home directory in Linux. A text file would open upon entering the command like the following:
Now, to export the LD_LIBRARY_PATH, go to the last line and add the following command:
A colon (:) separates all the paths in an environment variable. Therefore, we use a colon to add a new path.
Replace “/path” here with the path that you want to export. For your understanding, let’s take the “Documents” directory as an example:
After typing this command, save and exit the configuration file. In Bash, you can do it in three steps: press CTRL + X, Y, and Enter. Similarly, exit your respective files.
Moreover, this saves the file but it does not update in the current terminal session. Hence, enter the following command to implement the changes:
Replace “~/.bashrc” with the file paths that you used in the first step. It does not display anything upon execution.
Lastly, you must verify that the path is successfully added using the following command:
Note: If it does not show anything, you must have made a mistake in the previous steps. It might be a spelling issue or you missed a colon, other signs, etc. Therefore, follow all the steps correctly.
Conclusion
The LD_LIBRARY_PATH is a crucial environment variable in which you can set the paths to the shared libraries so that the programs can access them whenever needed. Since most users are deprived of its method, this guide focuses on explaining how to export the LD_LIBRARY_PATH in Linux using simple steps. This process often comes in handy when maintaining an organized file directory structure.