7

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?

matt3o
  • 901
  • 2
  • 8
  • 18
  • 3
    The symlink does indeed exist, but the question is, does the file that it points to exist? I.e. are you 100% sure that there *actually* exists an executable file at `/usr/local/bin/bin/julia-1.5.3/bin/julia`? – Jörg W Mittag Jan 01 '21 at 20:46
  • There is information missing I guess. I executed this in my home folder so the folder is at $HOME/bin/julia. Executing this command with the working directory in home leads to the described error. I used bash completetion for the paths so I am 100% sure they were correct when I called ln. – matt3o Jan 02 '21 at 18:05

1 Answers1

15

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.

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
matt3o
  • 901
  • 2
  • 8
  • 18
  • 14
    It doesn't *always* have to be absolute, it's just the reasonable thing to do in this case. Relative symlinks have their uses, or they wouldn't exist in the first place. – hobbs Jan 01 '21 at 17:50
  • Good comment! I just now tried to understand how a solution with a relative symlink would look like and upated the answer. – matt3o Jan 03 '21 at 11:03