linux.md

  1---
  2title: Building Zed for Linux
  3description: "Guide to building zed for linux for Zed development."
  4---
  5
  6# Building Zed for Linux
  7
  8## Repository
  9
 10Clone the [Zed repository](https://github.com/zed-industries/zed).
 11
 12## Dependencies
 13
 14- Install [rustup](https://www.rust-lang.org/tools/install)
 15
 16- Install the necessary system libraries:
 17
 18  ```sh
 19  script/linux
 20  ```
 21
 22  If you prefer to install the system libraries manually, you can find the list of required packages in the `script/linux` file.
 23
 24## Building from source
 25
 26Once the dependencies are installed, you can build Zed using [Cargo](https://doc.rust-lang.org/cargo/).
 27
 28For a debug build of the editor:
 29
 30```sh
 31cargo run
 32```
 33
 34And to run the tests:
 35
 36```sh
 37cargo test --workspace
 38```
 39
 40In release mode, the primary user interface is the `cli` crate. You can run it in development with:
 41
 42```sh
 43cargo run -p cli
 44```
 45
 46## Installing a development build
 47
 48You can install a local build on your machine with:
 49
 50```sh
 51./script/install-linux
 52```
 53
 54This builds `zed` and the `cli` in release mode, installs the binary at `~/.local/bin/zed`, and installs `.desktop` files to `~/.local/share`.
 55
 56> **_Note_**: If you encounter linker errors similar to the following:
 57>
 58> ```bash
 59> error: linking with `cc` failed: exit status: 1 ...
 60> = note: /usr/bin/ld: /tmp/rustcISMaod/libaws_lc_sys-79f08eb6d32e546e.rlib(f8e4fd781484bd36-bcm.o): in function `aws_lc_0_25_0_handle_cpu_env':
 61>           /aws-lc/crypto/fipsmodule/cpucap/cpu_intel.c:(.text.aws_lc_0_25_0_handle_cpu_env+0x63): undefined reference to `__isoc23_sscanf'
 62>           /usr/bin/ld: /tmp/rustcISMaod/libaws_lc_sys-79f08eb6d32e546e.rlib(f8e4fd781484bd36-bcm.o): in function `pkey_rsa_ctrl_str':
 63>           /aws-lc/crypto/fipsmodule/evp/p_rsa.c:741:(.text.pkey_rsa_ctrl_str+0x20d): undefined reference to `__isoc23_strtol'
 64>           /usr/bin/ld: /aws-lc/crypto/fipsmodule/evp/p_rsa.c:752:(.text.pkey_rsa_ctrl_str+0x258): undefined reference to `__isoc23_strtol'
 65>           collect2: error: ld returned 1 exit status
 66>   = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
 67>   = note: use the `-l` flag to specify native libraries to link
 68>   = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)
 69> error: could not compile `remote_server` (bin "remote_server") due to 1 previous error
 70> ```
 71>
 72> **Cause**:
 73> This is caused by known bugs in aws-lc-rs (no GCC >= 14 support): [FIPS fails to build with GCC >= 14](https://github.com/aws/aws-lc-rs/issues/569)
 74> & [GCC-14 - build failure for FIPS module](https://github.com/aws/aws-lc/issues/2010)
 75>
 76> You can refer to [linux: Linker error for remote_server when using script/install-linux](https://github.com/zed-industries/zed/issues/24880) for more information.
 77>
 78> **Workaround**:
 79> Set the remote server target to `x86_64-unknown-linux-gnu` like so `export REMOTE_SERVER_TARGET=x86_64-unknown-linux-gnu; script/install-linux`
 80
 81## Wayland & X11
 82
 83Zed supports both X11 and Wayland. By default, we pick whichever we can find at runtime. If you're on Wayland and want to run in X11 mode, use the environment variable `WAYLAND_DISPLAY=''`.
 84
 85## Notes for packaging Zed
 86
 87This section is for distribution maintainers packaging Zed.
 88
 89### Technical requirements
 90
 91Zed has two main binaries:
 92
 93- You will need to build `crates/cli` and make its binary available in `$PATH` with the name `zed`.
 94- 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.
 95- 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). You should also make this desktop file executable (`chmod 755`).
 96- 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/935cf542aebf55122ce6ed1c91d0fe8711970c82/script/bundle-linux#L65-L67) on your system.
 97- For an example of a complete build script, see [script/bundle-linux](https://github.com/zed-industries/zed/blob/935cf542aebf55122ce6ed1c91d0fe8711970c82/script/bundle-linux).
 98- 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."`.
 99- 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.
100
101### Other things to note
102
103Zed moves quickly, and distribution maintainers often have different constraints and priorities. The points below describe current trade-offs:
104
105- Zed is a fast-moving project. We typically publish 2-3 builds per week to address reported issues and ship larger changes.
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 versions of common developer tools, similar to rustup/rbenv/pyenv. This behavior is discussed [here](https://github.com/zed-industries/zed/issues/12589).
108- Users can install extensions locally and from [zed-industries/extensions](https://github.com/zed-industries/extensions). Extensions may install additional tools such as language servers. Planned safety improvements are tracked [here](https://github.com/zed-industries/zed/issues/12358).
109- Zed connects to several online services by default (AI, telemetry, collaboration). AI and our telemetry can be disabled by your users with their zed settings or by patching our [default settings file](https://github.com/zed-industries/zed/blob/main/assets/settings/default.json).
110- Because of the points above, Zed currently does not work well with sandboxes. See [this discussion](https://github.com/zed-industries/zed/pull/12006#issuecomment-2130421220).
111
112## Flatpak
113
114> Zed's current Flatpak integration exits the sandbox on startup. Workflows that rely on Flatpak's sandboxing may not work as expected.
115
116To build & install the Flatpak package locally follow the steps below:
117
1181. Install Flatpak for your distribution as outlined [here](https://flathub.org/setup).
1192. Run the `script/flatpak/deps` script to install the required dependencies.
1203. Run `script/flatpak/bundle-flatpak`.
1214. Now the package has been installed and has a bundle available at `target/release/{app-id}.flatpak`.
122
123## Memory profiling
124
125[`heaptrack`](https://github.com/KDE/heaptrack) is quite useful for diagnosing memory leaks. To install it:
126
127```sh
128$ sudo apt install heaptrack heaptrack-gui
129$ cargo install cargo-heaptrack
130```
131
132Then, to build and run Zed with the profiler attached:
133
134```sh
135$ cargo heaptrack -b zed
136```
137
138When this zed instance is exited, terminal output will include a command to run `heaptrack_interpret` to convert the `*.raw.zst` profile to a `*.zst` file which can be passed to `heaptrack_gui` for viewing.
139
140## Perf recording
141
142How to get a flamegraph with resolved symbols from a running Zed instance.
143Use this when Zed is using a lot of CPU. It is not useful for hangs.
144
145### During the incident
146
147- Find the PID (process ID) using:
148  `ps -eo size,pid,comm | grep zed | sort | head -n 1 | cut -d ' ' -f 2`
149  Or find the PID of `zed-editor` with the highest RAM usage in something
150  like htop/btop/top.
151
152- Install perf:
153  On Ubuntu (derivatives) run `sudo apt install linux-tools`.
154
155- Perf record:
156  Run `sudo perf record -p <pid you just found>`, wait a few seconds to gather data, then press Ctrl+C. You should now have a `perf.data` file.
157
158- Make the output file user owned:
159  run `sudo chown $USER:$USER perf.data`
160
161- Get build info:
162  Run zed again and type `zed: about` in the command pallet to get the exact commit.
163
164The `perf.data` file can be sent to Zed together with the exact commit.
165
166### Later
167
168This can be done by Zed staff.
169
170- Build Zed with symbols:
171  Check out the commit found previously and modify `Cargo.toml`.
172  Apply the following diff, then make a release build.
173
174```diff
175[profile.release]
176-debug = "limited"
177+debug = "full"
178```
179
180- Add the symbols to the perf database:
181  `perf buildid-cache -v -a <path to release zed binary>`
182
183- Resolve the symbols from the db:
184  `perf inject -i perf.data -o perf_with_symbols.data`
185
186- Install flamegraph:
187  `cargo install cargo-flamegraph`
188
189- Render the flamegraph:
190  `flamegraph --perfdata perf_with_symbols.data`
191
192## Troubleshooting
193
194### Cargo errors claiming that a dependency is using unstable features
195
196Try `cargo clean` and `cargo build`.