Change default JULIA Path Manually in Ubuntu

I have managed to locally install a latest Julia (version 1.5.2) locally on an Ubuntu SuperComputer into a folder I created called Julia_folder . I am able to use Julia within this folder. But my challenge is the system full path is still set to the old version 0.4.5 bin. I added my local Julia directory to my .bashrc file to manually change the default path using:

export PATH="$PATH:/path/to/home/clement/Julia_folder/julia-1.5.2/bin"

and applied the source .bashrc afterwards. But the path is still the old version 0.4.5 bin, and thus, my manually settings still didn’t work. How can I manually change the path to use the latest Julia version 1.5.2 instead of the old version 0.4.5 which was already installed in this Ubuntu Supercomputer? Please, I need assistance with this. Thanks in advance

Welcome!

Directories in the PATH are searched in order as they appear in the environment variable. If you want that /path/to/home/clement/Julia_folder/julia-1.5.2/bin has higher precedence over the rest of the PATH you have to prepend it, instead of appending it:

export PATH="/path/to/home/clement/Julia_folder/julia-1.5.2/bin:${PATH}"

Thanks for the response. I tried your suggestion by prepending as follows:

export PATH="/path/to/home/clement/Julia_folder/julia-1.5.2/bin:${PATH}"

However, it still could not achieve higher precedence over the default path in the Ubuntu system (ie. the Julia path for the old version).

How are you running Julia? Make sure the value of PATH is what you expect:

echo ${PATH}

Note that in the worst case you can start Julia just by using the absolute path of the executable you want to run

Please quote your code with triple backticks, to make it easier to read the messages: PSA: make it easier to help you

I am technically calling Julia in R via Ubuntu command line, but it couldn’t accept the JuliaCall since the version of Julia was an old one (v 0.4.5). So I installed a new version locally into a a new folder called Julia_folder. So my main goal is to be able to set the default Julia path to the new Julia version within my Julia_folder.

Typing

echo ${PATH}$

gives something very close

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/b??in:/home/clement/Julia_folder/julia-1.5.2/bin/julia:/home/clement/Julia_folder/julia-1.5.2/bin/julia

However, the Julia default Path is still that of the old Julia version 0.4.5. When I load Julia’s path using:

LOAD_PATH

it still gives me:

 "/usr/local/share/julia/site/v0.4"
 "/usr/share/julia/site" 

This seems wrong to me, the directory of Julia v1.5 appears at the end. It doesn’t look like the change you made was effective.

That’s what I have been battling with all day :disappointed:.

Where are you setting the variable exactly and how? To make the change effective you need to re-evaluate the setting of the variable. If you put it in your shell init script you need either to reload it, or simply to open a new shell

I added this code to my .bashrc shell script:

export PATH="/path/to/home/clement/Julia_folder/julia-1.5.2/bin:${PATH}"
and then run:

source .bashrc

Afterwards, running

echo $PATH
gives

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/b??in:/home/clement/Julia_folder/julia-1.5.2/bin/julia:/home/clement/Julia_folder/julia-1.5.2/bin/julia

That’s what I did. But I need it to access the Julia_folder directory as a default path.

And typing in the command line :

$ julia

as well as its

LOAD_PATH
returns the old version instead of the new one

A couple of things I notice.

Firstly, the PATH that you quote includes (twice) the string

/home/clement/Julia_folder/julia-1.5.2/bin/julia

That is the file that you’re trying to execute, not the directory that contains it. No matter where that is in your path, the operating system won’t find the executable.

Secondly, the line you have in your .bashrc,

export PATH="/path/to/home/clement/Julia_folder/julia-1.5.2/bin:${PATH}"

has not been successfully imported into your shell. Perhaps you didn’t do source ~/.bashrc after your most recent edit.

Finally, your Julia LOADPATH won’t change until you are running the correct executable. What do you get if you run which julia? If that gives the correct result, are you running R from the same shell?

1 Like

Running

which julia
gives me

/usr/bin/julia

Yes, I am running R from the same shell.

OK, so that’s the preinstalled julia. I don’t know why the edit of .bashrc didn’t work. Try typing

export PATH=/path/to/home/clement/Julia_folder/julia-1.5.2/bin:$PATH

on the bash command line. Does

which julia

give the same result?

Yes please, it gave me the same results:
/usr/bin/julia

If you followed the steps I gave, and

/path/to/home/clement/Julia_folder/julia-1.5.2/bin

is in your PATH before /usr/bin, then it seems that either

/path/to/home/clement/Julia_folder/julia-1.5.2/bin/julia

doesn’t exist, or it isn’t executable. Without any other information, I don’t think I can provide any other advice.

If there is a way of removing all the duplicate path in .bashrc, then I can start the whole process again?

There are two ways I can think of. The easiest one for long term stability of your Julia usage would be to edit your ~/.bashrc so that PATH is set the way that you want it, then start a new shell session.

The other way is to put something like the following into a text file (let’s call it fixpath):

/bin/sh
export PATH=/path/to/home/clement/Julia_folder/julia-1.5.2/bin:/usr/bin:/bin:/usr/sbin:/sbin

You would need to add the other directories that you need to that last line (maybe you can cut and paste from ~/.bashrc so you get the right list, leaving out the $PATH: section). Then you can do

source fixpath
1 Like

If you have root rights you could open your environment file, e.g., with

sudo gedit /etc/environment

and add your path (or edit the old path if it already exists)

/path/to/home/clement/Julia_folder/julia-1.5.2/bin

log off, and on again. Then typing julia in the terminal should start REPL.

I work on a HPC without root rights and start the computations via a script, e.g.,

#!/bin/sh

# set paths
homepath="/home/myHomeDir"
executable="$homepath/programs/julia/julia-1.1.0/bin/julia"
scriptfile="$homepath/myProgram/myMain.jl"

# set ld path
export LD_LIBRARY_PATH="$homepath/programs/julia/julia-1.1.0/lib":$LD_LIBRARY_PATH

# execute program
$executable $scriptfile 
1 Like

I haven’t had time to read the whole thread, sorry.
One thing to watch - if you are running a job on a compute node there is a difference between interactive and non-interactive shells. It can cuase problems like this.
HOWEVER your .bashrc file should be sourced so you should pick up the correct PATH

I now ask - is the MODULES environment installed on your HPC cluster?
Please send the output of module whatis
If modules are installed you can create a personal one in your own directory for Julia.

1 Like

If you are running your code vi a batch system please create a simpel batch script then run it, containg

printenv

1 Like

Thank you all for the great advice and assistance earlier today. My problem has been solved now. The .bash_profile shell script was the cause of the problem. I only needed to delete the .bash_profile shell script to save the day. Cheers. Now the new Julia version is set as the default path now as shown below:

/home/clement/bin:/home/clement/.local/bin:/home/clement/Julia_download/julia-1.5.3/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
1 Like