In the typical development case you would create a directory for your project.Documentation Index
Fetch the complete documentation index at: https://flox.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
flox init to create an environment for it,
then flox activate in that directory when you want to work on that project.
The packages in that environment are available when the environment is active,
and they’re unavailable otherwise.
But what about packages that you always want available?
Without Flox, you may turn to your system’s package manager
(apt, yum, brew, etc)
in order to install packages system-wide.
This has a number of drawbacks:
- You often only have a single package version to choose from.
- You often can’t install multiple versions of a package side-by-side.
- You can’t ensure that multiple machines get the exact same version.
- You may not be able to back up the list of installed packages.
default environment doesn’t have these problems,
so let’s take a look at how to set it up.
Initial setup
At the most basic level, thedefault environment is simply an environment
called default.
default environments are typically shared via FloxHub, but
you can also manage environments with git.
We refer to the environment associated with your user account as your
default environment.
In some cases Flox will prompt to set up your default environment for you.
To create the default environment yourself,
make sure you are logged in to FloxHub,
and initialize a FloxHub environment under your account:
Shorthand for default environmentYou can use
-D or --default as a shorthand for -r <youruser>/default.
For example: flox init -D is equivalent to flox init -r <youruser>/default.- Bash
- Zsh
- Fish
- Tcsh
Depending on the context, Bash will load different startup files.
For that reason, we need to add a line to two different files:
.bashrc and .profile.
Add the following line to the very end of each of those files:Once you’ve added that line to your shell, you’ll need to restart your shell (or open a new one) for the changes to take effect. If you don’t want to activate it automatically from your shell initialization scripts, you can activate the default environment explicitly when needed:
Taking it for a spin
Now let’s test out your newdefault environment.
If you’re in an arbitrary directory and apt install hello you would expect
it to be available no matter what directory you’re in.
Let’s do the same with Flox.
Let’s create a new temporary directory that we know doesn’t have an environment in it.
default
environment,
like you would expect from your system’s package manager:
Installing packages to the default environment from another Flox environment
If you’re in a project directory with an existing Flox environment, unsurprisingly, runningflox install <pkg> will install the package
to the environment in that directory, rather than your default environment.
Nevertheless, it’s still easy to install whatever you wish to your default
environment.
You can use the -D (or --default) flag as a shorthand:
Customization
Depending on when you created your default environment (the default was changed recently), you may also seeflox [default] as part of your prompt for every new shell.
You can configure that with a single command:
- Do show the Flox prompt
- Don't show the Flox prompt
Sharing
Since thedefault environment is “just” another FloxHub environment,
it’s possible to push this environment and share it between machines.
In fact, activating or initializing default environments on other machines
will link to the environment that is already on FloxHub.
To use the environment on other machines simply log in
and add the activation to your dotfiles as described above.
Changes made to the environment locally (e.g. newly installed packages) can be synchronized
with flox push and pull.
Generations
Pushing an environment creates the first version of the environment tracked on FloxHub, which is called a generation. To see how generations can be used to undo changes, edit the environment, perhaps adding a variableFOO = "bar" to the [vars] section.
Then push the environment to FloxHub:
Generations tab.
This should show the most recent generation created by the flox edit command.
To revert to the version of the environment prior to the edit, run rollback:
flox pull on another host, you’ll get the rolled-back
environment, without the edit.
Conclusion
Whether you want a reproducible package manager for your whole system, or you want reproducible, cross-platform developer environments, Flox has you covered. Even better, if you want both a package manager and developer environments, with Flox you only need to learn one tool.Detached and directory based default environments
Since default environments are normal Flox environments,
you can use any other environment the same way.
For example, you can:
Initialize a local environment, e.g. in your home directory:
If you choose to automatically activate the environment in your rc files, change the
flox activate -r <youruser> accordingly
to e.g. flox activate --dir ~.