Ubuntu – Why does the symlink to /usr/local/bin not work

command linejulia-langsymbolic-link

I installed Julia locally by unpacking it into a folder. Then I tried to add the executable to /usr/local/bin since I don't want to modify the $PATH.

sudo ln -s bin/julia-1.5.3/bin/julia /usr/local/bin/julia

If I now execute Julia in a new shell window the following message pops up:

$ julia
zsh: command not found: julia

$ ls -l /usr/local/bin/
total 12
lrwxrwxrwx 1 root root 25 Jan  1 10:08 julia -> bin/julia-1.5.3/bin/julia

So obviously the symlink exists nevertheless my shell tells me the command was not found. What is the problem here?

Best Answer

The solution is rather simple. Use an absolute symlink here such that the first argument of ln -s is a full path instead.

sudo ln -s /home/user/bin/julia-1.5.3/bin/julia /usr/local/bin/julia

Now it opens correctly and executes as expected.

The second and more complex solution is to use a relative symlink. However it has to be relative to the folder where the symlink will be created. Thus starting at /usr/local/bin one has to move up three folders to be at / and then descend into the appropriate folder.

sudo ln -s ../../../home/user/bin/julia-1.5.3/bin/julia /usr/local/bin/julia

Update: The comment below is correct and I edited the answer accordingly. Relative symlinks are fine and exist for good reasons however here they don't make any sense since they complicate the path a lot.

Related Question