# server.settings.Server.set_environment

- **Module:** server.settings.Server
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/server/settings.rs#L199
- **Page:** https://libtmux.org/reference/rs/server-settings-server-set_environment/

```
server.settings.Server.set_environment(self, name: &str, value: impl Into<OsString>) -> Result<(), Error>
```

Set a variable in the server's own environment.

tmux keeps this and each session's environment in separate stores, and
merges them only when it starts a process. So a name set here is
reported as an unknown variable by
[`Session::environment`](crate::Session::environment) -- reading
a session does not fall back to the server -- while a pane started
afterwards is handed it all the same.

Where both hold a name, the session's value is the one the process
gets. [`Self::hide_environment`] removes the name from the merge
entirely.

Panes already running keep the environment they were started with.

The value is marked sensitive, since an environment carries tokens.

# Errors

Returns an error when tmux rejects the name or value.

## Example

```rust
use libtmux::EnvironmentEntry;

let guard = libtmux::test::TestServer::new().await?;
let server = guard.server();

server.set_environment("EDITOR", "hx").await?;
assert!(matches!(
    server.environment("EDITOR").await?,
    Some(EnvironmentEntry::Set(value)) if value.as_bytes() == b"hx",
));

// Separate stores: the session has no entry of its own, and reading it
// does not fall back to the server. The value still reaches a process
// the session starts.
let session = server.new_session("separate").await?;
assert_eq!(session.environment("EDITOR").await?, None);

guard.shutdown().await?;
```
