linux.md

  1# Building Zed for Linux
  2
  3## Repository
  4
  5Clone down the [Zed repository](https://github.com/zed-industries/zed).
  6
  7## Dependencies
  8
  9- Install [Rust](https://www.rust-lang.org/tools/install). If it's already installed, make sure it's up-to-date:
 10
 11  ```bash
 12  rustup update
 13  ```
 14
 15- Install the necessary system libraries:
 16
 17  ```bash
 18  script/linux
 19  ```
 20
 21  If you prefer to install the system libraries manually, you can find the list of required packages in the `script/linux` file.
 22
 23## Backend dependencies
 24
 25> [!WARNING]
 26> This section is still in development. The instructions are not yet complete.
 27
 28If you are developing collaborative features of Zed, you'll need to install the dependencies of zed's `collab` server:
 29
 30- Install [Postgres](https://www.postgresql.org/download/linux/)
 31- Install [Livekit](https://github.com/livekit/livekit-cli) and [Foreman](https://theforeman.org/manuals/3.9/quickstart_guide.html)
 32
 33Alternatively, if you have [Docker](https://www.docker.com/) installed you can bring up all the `collab` dependencies using Docker Compose:
 34
 35```sh
 36docker compose up -d
 37```
 38
 39## Building from source
 40
 41Once you have the dependencies installed, you can build Zed using [Cargo](https://doc.rust-lang.org/cargo/).
 42
 43For a debug build of the editor:
 44
 45```
 46cargo run
 47```
 48
 49And to run the tests:
 50
 51```
 52cargo test --workspace
 53```
 54
 55In release mode, the primary user interface is the `cli` crate. You can run it in development with:
 56
 57```
 58cargo run -p cli
 59```
 60
 61## Installing a development build
 62
 63You can install a local build on your machine with:
 64
 65```
 66./script/install-linux
 67```
 68
 69This will build zed and the cli in release mode and make them available at `~/.local/bin/zed`, installing .desktop files to `~/.local/share`.
 70
 71If you'd like to install things to a different prefix you can use:
 72
 73```
 74./script/install-linux /usr/
 75```
 76
 77In this case the binary will be `/usr/bin/zed` and the `.desktop` file in `/usr/share`. The script should prompt for sudo as required so that the rust build runs as the current user.
 78
 79## Wayland & X11
 80
 81Zed has basic support for both modes. The mode is selected at runtime. If you're on wayland and want to run in X11 mode, you can set `WAYLAND_DISPLAY='' cargo run` to do so.
 82
 83## Notes for packaging Zed
 84
 85Thank you for taking on the task of packaging Zed!
 86
 87### Technical requirements
 88
 89Zed has two main binaries:
 90
 91* You will need to build `crates/cli` and make it's binary available in `$PATH` with the name `zed`.
 92* You will need to build `crates/zed` and put it at `$PATH/to/cli/../../libexec/zed-editor`. For example, if you are going to put the cli at `~/.local/bin/zed` put zed at `~/.local/libexec/zed-editor`. As some linux distributions (notably Arch) discourage the use of `libexec`, you can also put this binary at `$PATH/to/cli/../../lib/zed/zed-editor` (e.g. `~/.local/lib/zed/zed-editor`) instead.
 93* If you are going to provide a `.desktop` file you can find a template in `crates/zed/resources/zed.desktop.in`, and use `envsubst` to populate it with the values required. This file should also be renamed to `$APP_ID.desktop`, so that the file [follows the FreeDesktop standards](https://github.com/zed-industries/zed/issues/12707#issuecomment-2168742761).
 94* You will need to ensure that the necessary libraries are installed. You can get the current list by [inspecting the built binary](https://github.com/zed-industries/zed/blob/059a4141b756cf4afac4c977afc488539aec6470/script/bundle-linux#L65-L70) on your system.
 95* For an example of a complete build script, see [script/bundle-linux](https://github.com/zed-industries/zed/blob/main/script/bundle-linux).
 96* You can disable Zed's auto updates and provide instructions for users who try to Update zed manually by building (or running) Zed with the environment variable `ZED_UPDATE_EXPLANATION`. For example: `ZED_UPDATE_EXPLANATION="Please use flatpak to update zed."`.
 97* Make sure to update the contents of the `crates/zed/RELEASE_CHANNEL` file to 'nightly', 'preview', or 'stable', with no newline. This will cause Zed to use the credentials manager to remember a user's login.
 98
 99### Other things to note
100
101At Zed, our priority has been to move fast and bring the latest technology to our users. We've long been frustrated at having software that is slow, out of date, or hard to configure, and so we've built our editor to those tastes.
102
103However, we realize that many distros have other priorities. We want to work with everyone to bring Zed to their favorite platforms. But there is a long way to go:
104
105* Zed is a fast moving early-phase project. We typically release 2-3 builds a week to fix user-reported issues and release major features.
106* There are a couple of other `zed` binaries that may be present on linux systems ([1](https://openzfs.github.io/openzfs-docs/man/v2.2/8/zed.8.html), [2](https://zed.brimdata.io/docs/commands/zed)). If you want to rename our CLI binary because of these issues, we suggest `zedit`, `zeditor`, or `zed-cli`.
107* Zed automatically installs the correct version of common developer tools in the same way as rustup/rbenv/pyenv, etc. We understand that this is contentious, [see here](https://github.com/zed-industries/zed/issues/12589).
108* We allow users to install extensions on their own and from [zed-industries/extensions](https://github.com/zed-industries/extensions). These extensions may install further tooling as needed, such as language servers. In the long run we would like to make this safer, [see here](https://github.com/zed-industries/zed/issues/12358).
109* Zed connects to a number of online services by default (AI, telemetry, collaboration). AI and our telemetry can be disabled by your users with their own zed settings or by patching our [default settings file](https://github.com/zed-industries/zed/blob/main/assets/settings/default.json).
110* As a result of the above, zed currently does not play nice with sandboxes, [see here](https://github.com/zed-industries/zed/pull/12006#issuecomment-2130421220)
111
112## Flatpak
113
114> [!WARNING]
115> Zed's current Flatpak integration simply exits the sandbox on startup. Workflows that rely on Flatpak's sandboxing may not work as expected.
116
117To build & install the Flatpak package locally follow the steps below:
118
1191. Install Flatpak for your distribution as outlined [here](https://flathub.org/setup).
1202. Run the `script/flatpak/deps` script to install the required dependencies.
1213. Run `script/flatpak/bundle-flatpak`.
1224. Now the package has been installed and has a bundle available at `target/release/{app-id}.flatpak`.
123
124## Troubleshooting
125
126### Can't compile zed
127
128Before reporting the issue, make sure that you have the latest rustc version with `rustup update`.
129
130### Cargo errors claiming that a dependency is using unstable features
131
132Try `cargo clean` and `cargo build`.
133
134### Vulkan/GPU issues
135
136If Zed crashes at runtime due to GPU or vulkan issues, you can try running [vkcube](https://github.com/krh/vkcube) (usually available as part of the `vulkaninfo` package on various distributions) to try to troubleshoot where the issue is coming from. Try running in both X11 and wayland modes by running `vkcube -m [x11|wayland]`. Some versions of `vkcube` use `vkcube` to run in X11 and `vkcube-wayland` to run in wayland.
137
138If you have multiple GPUs, you can also try running Zed on a different one (for example, with [vkdevicechooser](https://github.com/jiriks74/vkdevicechooser)) to figure out where the issue comes from.