Offline installation of Julia packages

Thanks for your script! It’s exactly what i have been looking for.

It seems there have been some changes to BinaryPlatforms though.
On the host machine do the following

julia -e 'println(Base.BinaryPlatforms.triplet(Base.BinaryPlatforms.HostPlatform()))'

and copy the platform string that is returned.

The script from above then becomes

using Pkg

# copy platform string of the target machine from command above
platform_str = "x86_64-linux-gnu-libgfortran4-cxx11-libstdcxx26-julia_version+1.6.1"
platform = Base.BinaryPlatforms.parse( Base.BinaryPlatforms.Platform, platform_str )

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)

Edit: In the above script, you can also use this function

function add_package(name)
    Pkg.activate(tempname())
    ctx=Pkg.Types.Context()
    parsed_name = Pkg.REPLMode.parse_package_identifier(name; add_or_develop = true)
    Pkg.add(ctx, [parsed_name,]; platform=platform)
end

to download a package and its dependencies on the host machine into the DEPOT_PATH.
It works with git urls, too.

5 Likes