How to set the environmental variable LD_LIBRARY_PATH in linux

后端 未结 10 1426
独厮守ぢ
独厮守ぢ 2020-11-22 11:11

I have first executed the command: export LD_LIBRARY_PATH=/usr/local/lib

Then I have opened .bash_profile file: vi ~/.bash_profile

相关标签:
10条回答
  • 2020-11-22 11:23

    Add

    LD_LIBRARY_PATH="/path/you/want1:/path/you/want/2"

    to /etc/environment

    See the Ubuntu Documentation.

    CORRECTION: I should take my own advice and actually read the documentation. It says that this does not apply to LD_LIBRARY_PATH: Since Ubuntu 9.04 Jaunty Jackalope, LD_LIBRARY_PATH cannot be set in $HOME/.profile, /etc/profile, nor /etc/environment files. You must use /etc/ld.so.conf.d/.conf configuration files.* So user1824407's answer is spot on.

    0 讨论(0)
  • 2020-11-22 11:27

    You should add more details about your distribution, for example under Ubuntu the right way to do this is to add a custom .conf file to /etc/ld.so.conf.d, for example

    sudo gedit /etc/ld.so.conf.d/randomLibs.conf
    

    inside the file you are supposed to write the complete path to the directory that contains all the libraries that you wish to add to the system, for example

    /home/linux/myLocalLibs
    

    remember to add only the path to the dir, not the full path for the file, all the libs inside that path will be automatically indexed.

    Save and run sudo ldconfig to update the system with this libs.

    0 讨论(0)
  • 2020-11-22 11:27

    Put export LD_LIBRARY_PATH=/usr/local/lib in ~/.bashrc [preferably towards end of script to avoid any overrides in between, Default ~/.bashrc comes with many if-else statements]

    Post that whenever you open a new terminal/konsole, LD_LIBRARY_PATH will be reflected

    0 讨论(0)
  • 2020-11-22 11:31

    Alternatively you can execute program with specified library dir:

    /lib/ld-linux.so.2 --library-path PATH EXECUTABLE
    

    Read more here.

    0 讨论(0)
  • 2020-11-22 11:33

    You could try adding a custom script, say myenv_vars.sh in /etc/profile.d.

    cd /etc/profile.d
    sudo touch myenv_vars.sh
    sudo gedit myenv_vars.sh
    

    Add this to the empty file, and save it.

    export LD_LIBRARY_PATH=/usr/local/lib
    

    Logout and login, LD_LIBRARY_PATH will have been set permanently.

    0 讨论(0)
  • 2020-11-22 11:35

    I do the following in Mint 15 through 17, also works on ubuntu server 12.04 and above:

    sudo vi /etc/bash.bashrc 
    

    scroll to the bottom, and add:

    export LD_LIBRARY_PATH=.
    

    All users have the environment variable added.

    0 讨论(0)
提交回复
热议问题