How to set LD_LIBRARY_PATH permanently?

I am using Ubuntu 16. I want to use cfmid for my project. When I set LD_LIBRARY_PATH in terminal, I can get output of the cfmid library:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/lclab/installed/boost/boost_1_65_0:/home/lclab/installed/rdkit/rdkit-Release_2016_03_1/lib:/home/lclab/installed/lp/lp_solve_5.5.2.5_dev_ux64

But, when I close the terminal session and open a new one, I want to add LD_LIBRARY_PATH again.

How can I set this permanently?


Solution 1:

You just need to add the following line to your ~/.bashrc file:

LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/lclab/installed/boost/boost_1_65_0:/home/lclab/installed/rdkit/rdkit-Release_2016_03_1/lib:/home/lclab/installed/lp/lp_solve_5.5.2.5_dev_ux64"

The file is loaded every time you open a terminal. If you want to set the variable once when you login, add the line to ~/.profile instead.

Due to a bug in the openssh and/or xorg package the variable may be unset again on your system so that using the dotfiles as recommended above doesn’t work. There are several possible solutions:

  • disable the initialisation of ssh-agent in /etc/X11/Xsession.options:

    sudo sed -i 's/use-ssh-agent/no-use-ssh-agent/' /etc/X11/Xsession.options
    

    This won’t do any harm, see the explanation in this bug report comment.

  • the workaround from a duplicate bug report:

    echo STARTUP=\"/usr/bin/env LD_LIBRARY_PATH=\${LD_LIBRARY_PATH} \${STARTUP}\" | sudo tee /etc/X11/Xsession.d/90preserve_ld_library_path
    
  • use a /etc/ld.so.conf.d/*.conf file as explained in this bug report comment (see also How to set the environmental variable LD_LIBRARY_PATH in linux):

    echo "/opt/qt-mobility-src-1.0.0-tp2/install/lib" | sudo tee /etc/ld.so.conf.d/qt-mobility.conf && sudo ldconfig -v