I want to set an environment variable LD_LIBRARY_PATH which may or may not exist (it does not seem to exist currently, but I'm not sure if it will at some point). I have successfully managed to set my own vars, and extend the PATH variable as well, by placing my path.sh into /etc/profile.d/ and that works fine, however this new variable just does not seem to work. I have tried extending it or seting it new, with and without if / else (see screenshot). No matter what I do, it simply won't be added to the environment variables and I have no idea why (since it worked before). I did reboot, so that should not be the issue


For easier reading, here is the path.sh content in text form:

export PATH="$PATH:/snap/cmake/current/bin"
export unreal_path="/DevShared/UnrealEngine"
export GRPC_DIR="/DevShared/Dev_SRS/grpc/1.20.0"
export LD_LIBRARY_PATH="/DevShared/UnrealEngine"

#LD_LIBRARY_PATH may not exist
#if [ $LD_LIBRARY_PATH -z ]
#    export LD_LIBRARY_PATH="$ldPath"
#    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$ldPath"


Note that if I call the script via sudo bash /etc/profile.d/path.sh with the latter part executing rather than commented out, the bash actually does echo the correct path. Also, that ldPath variable was just for testing purposes, it is not actually necessary.


From Ubuntu help:

Note: You can only set this environment variable inside an interactive shell. 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. See Launchpad bug #366728 for more information.

LD_LIBRARY_PATH is reset for security reasons.

You need to add a conf file in /etc/ld.so.conf.d/

See also:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.