Two different versions of Julia are installed on Linux but there is only one ~/.julia/config/startup.jl
. I want to set different startup options for the two versions, can I? And how?
Thanks!
Two different versions of Julia are installed on Linux but there is only one ~/.julia/config/startup.jl
. I want to set different startup options for the two versions, can I? And how?
Thanks!
I think you can check the VERSION
constant, according to Strings · The Julia Language you can do stuff like
if v"0.2" <= VERSION < v"0.3-"
# do something specific to 0.2 release series
end
Oh I see… Thanks a lot!
Can I set different startup commands for different versions of Julia (or Julia in different installation directories)? And set different startup options according to the startup commands?
For example, I have two different Julia installations in ~/Julia1/
and ~/Julia2/
and they have different versions or the same version (can they?), and I want to start the Julia in ~/Julia1/
with command julia1
and julia2
for the other and let them load different startup options, can I?
Perhaps you want to set JULIA_DEPOT_PATH
for the different installations, or for different versions?
The discussion here appears to be related, but I don’t know whether it’s relevant.
If you want to manage multiple Julia versions I’d strongly recommend JuliaUp: GitHub - JuliaLang/juliaup: Julia installer and version multiplexer
Then you can do julia +1.8
etc to run a specific version.
You can use a symbolic link or shell alias to use the desired name for invoking a particular Julia installation. Inside your startup.jl file you can use Base.julia_cmd()[1]
to determine which one was invoked and conditionally execute different statements.
There’s no need to make symlinks, the output of Base.julia_cmd()
includes the full path, so you could do this sort of conditional:
if occursin("/Julia1/", Base.julia_cmd()
# Do your Julia1 stuff here
elseif occursin("/Julia2", Base.julia_cmd()
# Do your Julia2 stuff here
end
Note that searching for ~/Julia1/
won’t work because the path is fully qualified, it won’t contain the shortcut ~
but rather the full name of the user directory.
Did you read the full request? Specifically:
He wants to use commands other than “julia
” to launch Julia.
This is readily accomplished by naming the binaries julia1
and julia2
.
Based on the following information provided by the author of juliaup, it seems to be to be inadvisable to change the name of a file installed by juliaup:
It’s generally inadvisable to go changing the layout and names of files in a directory managed by another program, yes.
But this does not apply to a copy of the Julia binary stored in, as the original post indicates, ~/Julia1/
and ~/Julia2/
, those can be named whatever one wishes. julia1
and julia2
, for example.
You’re right. But if the OP takes the good advice offered earlier in this thread and uses juliaup to manage his future installs, then he should be aware that renaming those executables is not a good idea.
It’s worth knowing that juliaup
uses some indirection to manage versions, and that the actual binaries are found in ~/.julia/juliaup/$VERSION/bin
. Those can be symlinked or copied. Symlinks to ~/.juliaup/bin/julia
won’t work, because there’s a JSON file in ~/.juliaup
which the actual binary in question relies on to launch the currently-configured version of Julia.
So to OP: juliaup
is the best way to manage multiple versions of Julia, and if you want to put different versions in different directories, you can find them in the directory above. If you do symlink them, Base.julia_cmd()
will show the actual binary path, so if you want to put logic in startup.jl
which depends on the directory of the binary, you can either write that based on the directory where you find them, or copy the binaries into your directory, both will work.
Great! That’s exactly what I want! Thank you and everyone here for your kind help! Your answers are eye-opening!
I still have a small question: will it be legal if I have two Julia installations with the same version but in different directories?
This should be no problem, they will use the same packages, which should be ok: you can still configure any given environment to use different versions of a package, it’s just that the compiled caches will be shared on a per-version basis. I can’t imagine that will cause you problems.
I see! Thanks a lot!