How to set the environmental variable LD_LIBRARY_PATH in Linux?

There are plenty of ways in which we can set an environment variable in Linux and then make use of it later. Some ways provide us access to that variable in a particular window, in other cases, we can get access to those variables in every terminal window and in a permanent manner.

Let’s explore setting a new environment variable on an Ubuntu machine and then we can talk about setting the LD_LIBRARY_PATH.

In order to set a new environment variable, follow the commands shown below in sequence.

Command 1

Open your bash-profile with the command shown below −

vi ~/.bashrc

Command 2

Make use of the export linux utility command and insert the paste the command shown below in your bash-profile.

export GOPATH=/root/go_projects

Command 3

Exit the bash-profile and then source the profile with the command shown below.

source ~/.bashrc

Command 4

Open a new terminal to check that the environment variable you set is available to you.

echo $GOPATH

Output should look something like below −


If you don’t get any output, then make sure you followed the steps mentioned above correctly.

In case of LD_LIBRARY_PATH, we can follow the same steps as mentioned above, the command to change inside the bash-profile would look something like this −

export LD_LIBRARY_PATH = /path/to/your/library

And then you can source the file and make use of it.

Though it is recommended that you shouldn’t change the LD_LIBRARY_PATH as the other libraries and their dependencies might get broken, so it's better to append the path you want to the already existing LD_LIBRARY_PATH with the command shown below −

export LD_LIBRARY_PATH=$LD_LIBRARY_PAT:H/path/to/your/library

Now if you do echo $LD_LIBRARY_PATH



Updated on: 30-Jul-2021

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started