How do I stash the current Pkg environment for future use?

Assume I have a project using some packages which currently works, and I want to stash it away in case I need it again a year or so later. Is there an easy way to stash the current package environment, kind of like git stash?

I know I could manually construct a Project.toml and Manifest.toml with the current package versions, but I was hoping there was a way to automate this process.

If you are running in the default Julia environment (that is, if you haven’t done pkg> activate path/to/your/project, then you already have a Manifest and Project file, and you can find them in ~/.julia/dev/environments/v1.1/ (or /v1.0 if you’re using Julia 1.0).

If you want to preserve that global environment, I believe you can just copy those two files somewhere (preferrably somewhere under version control so you can track their changes in the future).

For example:

$ mkdir MyProject

$ cd myProject

# Copy the global environment into this project
$ cp ~/.julia/environments/v1.1/*.toml .

# Start Julia with this new environment
$ julia --project

# Make sure everything is working
(MyProject) pkg> test MyPackage

# Commit it
$ git init

$ git add Manifest.toml Project.toml

$ git commit -m "project works"

Nice. That works fine.

I do have a lot of packages installed though, most of which aren’t in use for this project. I should probably just get in the habit of giving each project its own environment.

Yes, I’d definitely recommend creating a new environment for each project. I really like that workflow.

By the way, you can safely remove packages you don’t need from the MyProject environment (via (MyProject) pkg> rm UselessPackage ), and that will only update the MyProject project and manifest files, without affecting your global package environment. So it should be possible to slim down MyProject after the fact.

1 Like