Offline installation of Julia packages

With the introduction of Artifacts in Pkg for Julia v1.3+, this simple script does the work, by calling julia with julia --project=/path/to/project

using Pkg
# On the host machine, call the following line to get the right 'machine' string corresponding to the host (here a Debian linux machine)
#machine=string(Sys.MACHINE,BinaryPlatforms.compiler_abi_str(BinaryPlatforms.detect_compiler_abi(platform_key_abi(Sys.MACHINE))))

machine="x86_64-pc-linux-gnu-libgfortran4-cxx11" # See above
platform = Pkg.BinaryPlatforms.platform_key_abi(machine)

path_to_project = # Fill this
path_to_external = # Fill this
ispath(path_to_external) || mkpath(path_to_external)
empty!(DEPOT_PATH)
push!(DEPOT_PATH,path_to_external)

function main(path_to_project,path_to_external,platform)
    Pkg.activate(path_to_project)
    ctx=Pkg.Types.Context()
    println("Project Path : " * path_to_project)
    println("Using : " * ctx.env.manifest_file * "\n"
           *"        " * ctx.env.project_file)
    println("Installing to " * path_to_external)
    println("Platform $platform")
    Pkg.instantiate(ctx;platform=platform,verbose=true)
end


main(path_to_project,path_to_external,platform)

It creates a new depot at path_to_external which can then be exported on the host machine.
On the host machine, you have to run JULIA_DEPOT_PATH=/path/to/exported/depot julia and launch using Pkg; Pkg.build().

You might have some problems with not found libraries, but don’t worry it is generally just a symlink/renaming problem.

Note that if your project use Conda/PyCall, it won’t install a proper python distribution corresponding to your machine, you have to install it manually and specify the CONDA_JL_HOME environment variable.

For Plots.jl with GR (unfortunately not using Pkg.Artifacts for the moment) you have to directly download the library at https://github.com/sciapp/gr/releases, install it in GR/###/deps/downloads and remove this line in GR/###/deps/build.jl
https://github.com/jheinen/GR.jl/blob/b275fcf52800018fd272ec9baa0259759f9b9801/deps/build.jl#L134

7 Likes