Automatic package update in startup.jl

Thanks to stacked environments, I only have two packages in my global environment: Revise.jl and EmacsVterm.jl.

I am wondering if there is a way to keep them automatically updated without (significant) user intervention. I could put a

import Pkg
Pkg.update()

in my startup.jl, but that would add a significant delay to every time I start up Julia.

Is there a simple way to

  1. check if I am online (other than the standard tricks, eg calling nslookup with a short timeout)

  2. query last time an environment was updated?

Would

import Pkg
if isinteractive()
    Threads.@spawn Pkg.update()
end

In the startup.jl work for you?
It would try to update in the background every time you spawn an interactive process.

1 Like

An other approach could be to have a daily (ana)cron[1] job that tries to perform the update. Maybe you don’t even have to check whether you’re online or not: since in this case it would be a non-interactive process, I think you can afford to let it fail silently when you’re offline; it will still fulfill its purpose if it succeeds at least every few days.


  1. or any similar tool depending on your OS ↩︎

1 Like

The other options are nice. However, I do think it is good to update each time.

If you want to update, I have a small script to update periodically the julia version and all shared environment, but I only run one time after several weeks, this is:

#!/usr/bin/env bash
juliaup update
cd ~/.julia/environments || exit

for dir in *; do
    if ! [ -d  "$dir" ]; then
       continue
    fi

    cd "$dir" || continue
    julia -e 'using Pkg; Pkg.activate("."); Pkg.update(); Pkg.gc()'
    cd ..
done

As I said, it is very slow, so I usually put when I am working on other things, not with Julia :-).

1 Like