# Server.init(tmuxExecutable:configurationFile:environment:)

- **Package:** libtmux-swift
- **Language:** Swift
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-swift/blob/e72fb5c17ab54996233b76b037c3b94a46e55685/Sources/LibTmux/Server.swift#L314
- **Page:** https://libtmux.org/en/swift/latest/reference/server-init(tmuxexecutable-configurationfile-environment-)/

```
init(
    tmuxExecutable: String, configurationFile: String?,
    environment: [String: String])
```

A server on the socket the environment names, else on the one tmux picks.

`LIBTMUX_SOCKET_PATH` names a socket path, passed to tmux as `-S`.
Otherwise `LIBTMUX_SOCKET` names a socket name, passed as `-L`. With
neither set the server's ``endpoint`` is ``Endpoint/tmuxChoice``: tmux is
passed no socket and chooses the server itself, the one in `TMUX` inside
tmux and the default socket in `TMUX_TMPDIR` elsewhere. The path wins when
both variables are set, as it does for the Python library. A variable that
is empty or only whitespace counts as unset, each one on its own, so a
blank path leaves a set name in force; any other value is used as written.

Name a socket with ``init(socketPath:tmuxExecutable:configurationFile:)``
or ``init(socketName:tmuxExecutable:configurationFile:)`` when the answer
must not depend on the environment; those leave both variables unread.
Only the two variables are read from `environment`. Every tmux process the
server starts inherits the process's own environment, `TMUX` included.

- Parameter environment: where to read the two variables from.
- Throws: ``TmuxError/invalidEndpoint(_:)`` for a socket path that is too
  long. The error names the length and never the value.

## Examples

```swift
let server = try Server()
let sessions = try await server.sessions()
```

## Parameters

- `tmuxExecutable` (`String`)
- `configurationFile` (`String?`)
- `environment` (`[String : String]`)

## Raises

- [`TmuxError`](/en/swift/latest/reference/tmuxerror/)
