Hard reset of Julia environment

Hello,
I need to reset a julia environment from all temporary files, like in a fresh installation after a mess I made that is causing many packages to fail precompiliation and loading.

In particular, after I activate the environment, the ForwardDiff precompilation fails with error:

ERROR: LoadError: TypeError: non-boolean (String) used in boolean context
Stacktrace:
 [1] top-level scope
   @ ~/.julia/packages/ForwardDiff/vXysl/src/partials.jl:93

This error only occurs in one environment (not in the basic one), and probably is related to an error I did with Preferences.jl setting “nansafe_mode” to “true” (the error started manifesting after that).

How can I reset the full enviroment, cleaning all cache, global variables, precompilation cache, forcing julia to reinitialize it from scratch? I tried Pkg.update() but it still fails in precompiling ForwardDiff on that environment.

EDIT:
Ok I solved the error with ForwardDiff (I managed to find the variable in LocalPreferences.toml and fix the “true” to true). However the question remains as it happened before to have messed up something and having hard time figuring out how to solve the problem. Is there a simple way to force julia to reset the environment?

1 Like

One way to accomplish some of this is to copy your Project.toml to a new directory and then Pkg.instantiate() it.

using Pkg
d = mktempdir()
cp(Base.active_project(), joinpath(d,"Project.toml"))
Pkg.instantiate()

The only way to really reset all global variables is to restart Julia.

To reset the precompile cache you need to remove the ~/.julia/compiled/v1.9 directory or subdirectories.

More precisely,

compilecache_path = joinpath(DEPOT_PATH[1], "compiled", "v$(VERSION.major).$(VERSION.minor)")