How to install the newest version of a package?

How can I install the latest version of a package?

If I have for example KiteModels v0.6.3 installed before (in a different project) and then do:

mkdir test
cd test
julia --project="."

and try to install KiteModels with:

using Pkg
pkg"add KiteModels"

it will install the old version of KiteModels in the new project, but not the latest version of KiteModels.

Which sequence of commands ensures that I get the latest, released version of KiteModels?

I know I can do:

add KiteModels#main

to get the last, unreleased version. Is there a similar command to get the last released version?

The context is not entirely clear but guessing that you want to get a rather recently registered version you could look into the β€œeager” package server option. See 7. Registries Β· Pkg.jl.

Iteresting. But no, I just want to know how I can explain to my students or partners how to install the latest, released version of my package, assuming the package servers have finished their update.

I could do:

using Pkg
pkg"add KiteModels"
pkg"update"

But is that the best way to do it?

It might precompile first the old version and then the new version. It might also update other packages than KiteModels even if that is not required.

1 Like

Assuming there’s nothing else in the environment holding it back, I would try

pkg> update KiteModels

Do you have the env variable JULIA_PKG_PRESERVE_TIERED_INSTALLED set? Otherwise the default should be to install the latest version, assuming it doesn’t conflict with another package, and assuming the registry is up-to-date (and the registry will by default update on the first pkg operation of the julia session, or when update is called).

3 Likes

No, the default is tiered, and that does NOT install the latest version:

 Argument         Description                                                                       
  –––––––––––––––– ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
  installed        Like all except also only add versions that are already installed                 
  all              Preserve the state of all existing dependencies (including recursive dependencies)
  direct           Preserve the state of all existing direct dependencies                            
  semver           Preserve semver-compatible versions of direct dependencies                        
  none             Do not attempt to preserve any version information                                
  tiered_installed Like tiered except first try to add only installed versions                       
  tiered           Use the tier that will preserve the most version information while                
                   allowing version resolution to succeed (this is the default)  

Perhaps this command would install the latest version:

pkg"add --preserve none KiteModels"

?

Update: Doesn’t work, installs an old version.

So for now I stick with:

using Pkg
pkg"add KiteModels"; pkg"up"

But it is annoying that Pkg.add has no option to install the latest version.

Tiered tries to not change other existing versions, but in your example you are creating a new environment and adding KiteModels to it (alone) so there are no other versions to preserve. That’s why Gunnar is asking you about registry eagerness and I’m asking about ENV variables; it sounds like something else is happening or something is going wrong.

1 Like

I have no Julia related env variables. I just had an old version - in a different project - installed before. I think Pkg re-uses packages from other project and doesn’t install and precompiles them again if you start a new project.

Do you have something in the environment that could clamp version of KiteModels?

No, it is a fresh, empty project. And Pkg.update() works.

That’s what tiered_installed does which is not the default. That sounds like a bug then. What version of Julia are you using?

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 Γ— AMD Ryzen 7 7840U w/ Radeon  780M Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

I can’t replicate.

$ mkdir /tmp/testdepot                   # Create an empty depot.
$ JULIA_DEPOT_PATH=/tmp/testdepot julia  # Start Julia 1.10.4 like freshly installed.
(@v1.10) pkg> add KiteModels@0.6.3       # Add 0.6.3 to global environment.
julia> using KiteModels                  # Load it for good measure.
(@v1.10) pkg> activate --temp            # Create an empty environment.
(jl_kSO7yU) pkg> add KiteModels          # Add KiteModels, installs 0.6.4.

Do you have a startup.jl file?

Does

pkg> activate --temp
pkg> add KiteModels@0.6.4

work and/or give any interesting output?

I wrote this test script:

#!/bin/bash -eu
rm -rf /tmp/testdepot
mkdir /tmp/testdepot
rm -rf /tmp/test
mkdir /tmp/test
cd /tmp/test
export JULIA_DEPOT_PATH=/tmp/testdepot 
julia --project="." -e "using Pkg; pkg\"add KiteModels#v0.6.3\"; using KiteModels"
cd ..
rm -rf /tmp/test2   
mkdir /tmp/test2
cd /tmp/test2
julia --project="." -e "using Pkg; pkg\"add KiteModels\"; using KiteModels; pkg\"status\""
cd ..

It indicates that Pkg.add installs the latest version of my package under the given test conditions.

So perhaps I had an outdated registry. Where is the registry stored? Is there one registry stored per project, or one per Julia depot? When does Julia fetch a new version of the registry? Is there a command to force that?

The registry is usually stored in the depot. The default location is ~/.julia/registries/.

See the registry update command.

(@v1.10) pkg> help registry update
  registry [up|update]
  registry [up|update] reg...

  Update package registries reg.... If no registries are specified all
  registries will be updated.

  Examples

  pkg> registry up
  pkg> registry up General
2 Likes

A question I’ve asked myself a few times and which seems closely related enough that I don’t think I’m hijacking the thread here:

Is there a command to simply get latest released version of a package? I normally just check GitHub manually, but would be interested to hear about programmatic solutions.

possibly useful code:

but … β€œuse juliahub” I suppose.

1 Like

Can I use JuliaHub from the REPL though?

easier to grep through the packages directory perhaps ? - no, that might not work.