Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an executable that requires a shared library that resides in /opt/... folder. I have included the path in LD_LIBRARY_PATH under /etc/environment and updated it using source /etc/environment. When I run this executable without root permissions, I get an error saying libxxx.so: cannot open shared object file: No such file or directory. But when I run it with sudo, it runs. Though the problem is, the license is not under root user, therefore it throws an error regarding license. I changed the permission for /opt/... so that the normal user can create and delete files. Though, it does not help. What's wrong and how do I fix this?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

/etc/environment is interpreted during login. So the correct way to see the changes you made to /etc/environment is to logout and login again.

sudo works because it partially emulates login as root (sudo -i emulates the login even more accurately).

source /etc/environment won't work, because source is a shell command that tells the shell to interpret the given file as a shell script. The problem is: /etc/environment is not a shell script. It is a list of environment variable name-value pair in the format:

name="value"

That line, for a shell, is the definition of a global variable, which can be seen only by shell itself. Programs executed from the shell can't see it. The correct way to define an environment variable is using the export shell command:

export name="value"

So, if you really want to use your brand new LD_LIBRARY_PATH without logging out, you should execute the following command instead of source /etc/environment:

export LD_LIBRARY_PATH="/opt/..."

UPDATE: LD_LIBRARY_PATH cannot be set into /etc/environment because of ssh-agent. For details see bug #47958 and the Ubuntu wiki page on environment variables. As specified in the wiki page, a workaround exists and consists in using /etc/ld.so.conf.d.

For example, you could create /etc/ld.so.conf.d/opt.conf with the following contents:

# Paths for my cool libraries
/opt/...

Although this is listed as a workaround, ld.so.conf.d is actually the most appropriate place for such settings.

share|improve this answer
    
Thanks. I logged out and logged in. When I do echo $LD_LIBRARY_PATH, I get nothing. While I executed the same command under root, it prints the path in /etc/environment. I execute the export command and it's fine now. However, isn't this temporary? If I close the shell, it's gone? Why isn't the non-root user picking the path from the environment file? –  user592748 May 7 '13 at 16:53
    
@user592748: you are right. Whilst what I have said is true and applies to the general case, LD_LIBRARY_PATH gets unset by ssh-agent during login. I have updated my answer to include a workaround. –  Andrea Corbellini May 7 '13 at 17:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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