|
| 1 | +--- |
| 2 | +title: flox activate |
| 3 | +description: Command reference for the `flox activate` command. |
| 4 | +--- |
| 5 | + |
| 6 | +# `flox activate` command |
| 7 | + |
| 8 | +## NAME |
| 9 | + |
| 10 | +flox-activate - activate environments |
| 11 | + |
| 12 | +## SYNOPSIS |
| 13 | + |
| 14 | + flox [<general-options>] activate |
| 15 | + [-d=<path> | -r=<owner>/<name>] |
| 16 | + [-t] |
| 17 | + [--print-script] |
| 18 | + [-- <command> [<arguments>]] |
| 19 | + |
| 20 | +## DESCRIPTION |
| 21 | + |
| 22 | +Sets environment variables and aliases, runs hooks, starts services, and |
| 23 | +adds `bin` directories to your `$PATH`. |
| 24 | + |
| 25 | +`flox activate` may run in one of three modes: |
| 26 | + |
| 27 | +- interactive: `flox activate` when invoked from an interactive shell |
| 28 | + Launches an interactive sub-shell. The shell to be launched is |
| 29 | + determined by `$FLOX_SHELL` or `$SHELL`. |
| 30 | +- command: `flox activate -- CMD` |
| 31 | + Executes `CMD` in the same environment as if run inside an interactive |
| 32 | + shell produced by an interactive `flox activate` The shell `CMD` is |
| 33 | + run by is determined by `$FLOX_SHELL` or `$SHELL`. |
| 34 | +- in-place: `flox activate` when invoked from an non-interactive shell |
| 35 | + with it’s `stdout` redirected e.g. `eval "$(flox activate)"` |
| 36 | + Produces commands to be sourced by the parent shell. Flox will |
| 37 | + determine the parent shell from `$FLOX_SHELL` or otherwise |
| 38 | + automatically determine the parent shell and fall back to `$SHELL`. |
| 39 | + |
| 40 | +`flox activate` currently supports `bash`, `fish`, `tcsh`, and `zsh` |
| 41 | +shells for any of the detection mechanisms described above. |
| 42 | + |
| 43 | +When invoked interactively, the shell prompt will be modified to display |
| 44 | +the active environments, as shown below: |
| 45 | + |
| 46 | + flox [env1 env2 env3] <normal prompt> |
| 47 | + |
| 48 | +When multiple environments are activated each of their shell hooks |
| 49 | +(`profile` and `hook` scripts) are executed in the context of the |
| 50 | +environment that they come from. This means that for each shell hook |
| 51 | +various environment variables such as `PATH`, `MANPATH`, |
| 52 | +`PKG_CONFIG_PATH`, `PYTHONPATH`, etc, are set to the appropriate values |
| 53 | +for the environment in which the shell hook was defined. See |
| 54 | +[`manifest.toml(5)`](./manifest.toml.md) for more details on shell |
| 55 | +hooks. |
| 56 | + |
| 57 | +## OPTIONS |
| 58 | + |
| 59 | +### Activate Options |
| 60 | + |
| 61 | +`-- <command> [<arguments>]` |
| 62 | +Command to run in the environment. Spawns the command in a subshell that |
| 63 | +does not leak into the calling process. |
| 64 | + |
| 65 | +`-t`, `--trust` |
| 66 | +Trust a remote environment for this activation. Activating an |
| 67 | +environment executes a shell hook which may execute arbitrary code. This |
| 68 | +presents a security risk, so you will be prompted whether to trust the |
| 69 | +environment. Environments owned by the current user and Flox are always |
| 70 | +trusted. You may set certain environments to always be trusted using the |
| 71 | +config key `trusted_environments."<owner/name>" = (trust | deny)`, or |
| 72 | +via the following command: |
| 73 | +`flox config --set trusted_environments.\"<owner/name>\" trust`. |
| 74 | + |
| 75 | +`--print-script` |
| 76 | +Prints an activation script to `stdout` that’s suitable for sourcing in |
| 77 | +a shell rather than activation via creating a subshell. `flox` |
| 78 | +automatically knows when to print the activation script to `stdout`, so |
| 79 | +this command is just a debugging aid for users. |
| 80 | + |
| 81 | +`-s`, `--start-services` |
| 82 | +Start the services listed in the manifest when activating the |
| 83 | +environment. If no services are running, the services from the manifest |
| 84 | +will be started, otherwise a warning will displayed and activation will |
| 85 | +continue. |
| 86 | + |
| 87 | +This flag is currently incompatible with “in-place” activations and |
| 88 | +remote environments, but these features will be added in the future. |
| 89 | + |
| 90 | +The services started with this flag will be cleaned up once the last |
| 91 | +activation of this environment terminates. |
| 92 | + |
| 93 | +A remote environment can only have a single set of running services, |
| 94 | +regardless of how many times the environment is activated concurrently. |
| 95 | + |
| 96 | +### Environment Options |
| 97 | + |
| 98 | +If no environment is specified for an environment command, the |
| 99 | +environment in the current directory or the active environment that was |
| 100 | +last activated is used. |
| 101 | + |
| 102 | +`-d`, `--dir` |
| 103 | +Path containing a .flox/ directory. |
| 104 | + |
| 105 | +`-r`, `--remote` |
| 106 | +A remote environment on FloxHub, specified in the form `<owner>/<name>`. |
| 107 | + |
| 108 | +### General Options |
| 109 | + |
| 110 | +`-h`, `--help` |
| 111 | +Prints help information. |
| 112 | + |
| 113 | +The following options can be passed when running any `flox` subcommand |
| 114 | +but must be specified *before* the subcommand. |
| 115 | + |
| 116 | +`-v`, `--verbose` |
| 117 | +Increase logging verbosity. Invoke multiple times for increasing detail. |
| 118 | + |
| 119 | +`-q`, `--quiet` |
| 120 | +Silence logs except for errors. |
| 121 | + |
| 122 | +## ENVIRONMENT VARIABLES |
| 123 | + |
| 124 | +### Variables set by `flox activate` |
| 125 | + |
| 126 | +`$FLOX_ENV` |
| 127 | +Contains the path to the built environment. This directory contains a |
| 128 | +merged set of `bin`, `lib`, etc directories for all the packages in the |
| 129 | +environment. |
| 130 | + |
| 131 | +`$FLOX_PROMPT_ENVIRONMENTS` |
| 132 | +Contains a space-delimited list of the active environments, |
| 133 | +e.g. `owner1/foo owner2/bar local_env`. If, `hide_default_prompt` is set |
| 134 | +to `true`, environments named `default` are excluded. |
| 135 | + |
| 136 | +`$FLOX_ENV_CACHE` |
| 137 | +`activate` sets this variable to a directory that can be used by an |
| 138 | +environment’s hook to store transient files. These files will persist |
| 139 | +for environments used locally, but they will not be pushed, and they |
| 140 | +will not persist when using a remote environment with `-r`. |
| 141 | + |
| 142 | +`$FLOX_ENV_PROJECT` |
| 143 | +`activate` sets this variable to the directory of the project using the |
| 144 | +flox environment. For environments stored locally, this is the directory |
| 145 | +containing the environment. When running `flox activate -r`, this is set |
| 146 | +to the current working directory. This variable can be used to find |
| 147 | +project files in environment hooks. |
| 148 | + |
| 149 | +`$_FLOX_ACTIVE_ENVIRONMENTS` |
| 150 | +A JSON array containing one object per active environment. This is |
| 151 | +currently an implementation detail and its contents are subject to |
| 152 | +change. |
| 153 | + |
| 154 | +`$FLOX_ACTIVATE_START_SERVICES` |
| 155 | +`"true"` if this activation started services, `"false"` otherwise. |
| 156 | + |
| 157 | +### Variables used by `flox activate` |
| 158 | + |
| 159 | +`$FLOX_SHELL` |
| 160 | +When launching an interactive sub-shell, Flox launches the shell |
| 161 | +specified in `$FLOX_SHELL` if it is set. When printing a shell for |
| 162 | +sourcing in the current shell, Flox will produce a script suitable for |
| 163 | +`$FLOX_SHELL` if it is set. |
| 164 | + |
| 165 | +`$SHELL` |
| 166 | +When launching an interactive sub-shell, Flox launches the shell |
| 167 | +specified in `$SHELL` if it is set and `$FLOX_SHELL` is not set. When |
| 168 | +printing a shell for sourcing in the current shell, Flox will produce a |
| 169 | +script suitable for `$SHELL` if it is set and `$FLOX_SHELL` is not set |
| 170 | +and Flox can’t detect the parent shell. |
| 171 | + |
| 172 | +`$FLOX_PROMPT_COLOR_{1,2}` |
| 173 | +Flox adds text to the beginning of the shell prompt to indicate which |
| 174 | +environments are active. A set of default colors are used to color this |
| 175 | +prompt, but the colors may be overridden with the `$FLOX_PROMPT_COLOR_1` |
| 176 | +and `$FLOX_PROMPT_COLOR_2` environment variables. |
| 177 | + |
| 178 | +The values of these variables should be integers chosen from the |
| 179 | +256-color palette as described in the [xterm-256color |
| 180 | +chart](https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg). |
| 181 | + |
| 182 | +## EXAMPLES: |
| 183 | + |
| 184 | +Activate an environment stored in the current directory: |
| 185 | + |
| 186 | + $ flox activate |
| 187 | + |
| 188 | +Activate an environment `some_user/myenv` that’s been pushed to FloxHub: |
| 189 | + |
| 190 | + $ flox activate -r some_user/myenv |
| 191 | + |
| 192 | +Invoke a command inside an environment without entering its subshell: |
| 193 | + |
| 194 | + $ flox activate -- cmd --some-arg arg1 arg2 |
| 195 | + |
| 196 | +Activate `default` Flox environment only within the current shell (add |
| 197 | +to the relevant “rc” file, e.g. `~/.bashrc` or `~/.zprofile`): |
| 198 | + |
| 199 | + $ eval "$(flox activate)" |
| 200 | + |
| 201 | +## SEE ALSO |
| 202 | + |
| 203 | +[`flox-push(1)`](./flox-push.md), [`flox-pull(1)`](./flox-pull.md), |
| 204 | +[`flox-edit(1)`](./flox-edit.md), [`flox-delete(1)`](./flox-delete.md) |
0 commit comments