How to give a valid uuid to an existing package and how to "desactivate" an environment?

Hello and a happy new year to everyone,

I have two simple questions concerning the basic use of Pkg. Browsing the forum I found some topics discussing those issues, but I could not really understand the answers.
I would be very happy if someone could indicate a solution to the following:

  1. I have packages that I generated using PkgDev.generate in Julia 0.6. These packages have no uuid. What is the recommended way to give them a valid uuid in julia 0.7 and higher? Should I use the new generate function (which I would like to avoid)? Or is there another way?

  2. How do I “desactivate” one of my own packages in the Pkg repl mode?
    For instance:

shell> cd /MyJuliaPackages/MyPackage/
julia> ]
(v1.0) pkg> activate .
(MyPackage) pkg>

How do I get back to the original (v1.0) environment without doing cd into the v1.0 environment?

Many thanks in advance,

1 Like

I just found the answer to my second question:

shell> cd /MyJuliaPackages/MyPackage/
julia> ]
(v1.0) pkg> activate .
(MyPackage) pkg>
(MyPackage) pkg> activate
(v1.0) pkg>

Still looking for an answer to my first question.

Pkg has a built in generate command you can use which gives the project a uuid. For example, you can do pkg> generate MyPackage which will create a ./MyPackage directory. ./MyPackage/Project.toml will have a UUID. This is the recommended way to start a new project.

You can also manually create your own UUID:

import UUIDs

You might also want to read the quick guide for Pkg. Or perhaps even the full manual.


Thanks for your help and the links.

Actually, I found the answers to my question in a previous answer of yours in this post.

That was really helpful.

Thanks again

1 Like

Note: This was only necessary for packages there were registered in both the old METADATA system and the new registry system. It has not been necessary for years and the functionality described has been deleted. If you need a UUID for a new package, you can use the UUIDs.uuid4() function to generate a random UUID or use a package templater Pkg.generate() or PkgTemplates which will generate a random UUID for you.

If you’re planning on registering the package any time soon, you need to use this utility function to generate a METADATA-compatible UUID:

julia> import Pkg

julia> Pkg.METADATA_compatible_uuid("MyPkg")

If you’re not planning on registering it (in the near future) then you can generate a random UUID using one of the UUID-generating functions. I recommend uuid4 to generate a random UUID:

julia> uuid4()

The uuid1 function is time-based, which seems less safe than a fully random UUID.


Huh, I wasn’t aware of that function. Thanks for clarifying :smile:

This still pops up on google when searching for package uuids, and it seems it is outdated advice, right? METADATA_compatible_uuid is now removed (in this commit and we should just use UUIDs.uuid4()

Yes, this advice was only for packages that were migrating from the old METADATA registry to the new General registry and needed a consistent UUID. If you are creating a new package, you should use PkgTemplates, which generates a random UUID for you.

1 Like

The above solution is outdated and no longer works with Julia 1.6. I posted an updated question here: How to create a UUID for a Julia Package? - Stack Overflow since this post is still the top search result.

It was also only ever meant for the time period before Julia 1.0 when people were registering packages in both METADATA and the new registry. There’s been a Pkg.generate() function that does this correctly for you and various other templates packages too. Which is exactly what I already said in my last post in 2020.


Yes, sorry, wasn’t trying to say otherwise, just wanted to leave that note as a more general comment in case someone stumbles upon the thread like I did and was only skimming through it.