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### Linkers {#linker}
 25
 26On Linux, Rust's default linker is [LLVM's `lld`](https://blog.rust-lang.org/2025/09/18/Rust-1.90.0/). Alternative linkers, especially [Wild](https://github.com/davidlattimore/wild) and [Mold](https://github.com/rui314/mold), can improve clean and incremental build times.
 27
 28Zed currently uses Mold in CI because it is more mature. For local development, Wild is recommended because it is typically 5-20% faster than Mold.
 29
 30These linkers can be installed with `script/install-mold` and `script/install-wild`.
 31
 32To use Wild as your default, add these lines to your `~/.cargo/config.toml`:
 33
 34```toml
 35[target.x86_64-unknown-linux-gnu]
 36linker = "clang"
 37rustflags = ["-C", "link-arg=--ld-path=wild"]
 38
 39[target.aarch64-unknown-linux-gnu]
 40linker = "clang"
 41rustflags = ["-C", "link-arg=--ld-path=wild"]
 42```
 43
 44To use Mold as your default:
 45
 46```toml
 47[target.'cfg(target_os = "linux")']
 48rustflags = ["-C", "link-arg=-fuse-ld=mold"]
 49```
 50
 51## Building from source
 52
 53Once the dependencies are installed, you can build Zed using [Cargo](https://doc.rust-lang.org/cargo/).
 54
 55For a debug build of the editor:
 56
 57```sh
 58cargo run
 59```
 60
 61And to run the tests:
 62
 63```sh
 64cargo test --workspace
 65```
 66
 67In release mode, the primary user interface is the `cli` crate. You can run it in development with:
 68
 69```sh
 70cargo run -p cli
 71```
 72
 73## Installing a development build
 74
 75You can install a local build on your machine with:
 76
 77```sh
 78./script/install-linux
 79```
 80
 81This builds `zed` and the `cli` in release mode, installs the binary at `~/.local/bin/zed`, and installs `.desktop` files to `~/.local/share`.
 82
 83> **_Note_**: If you encounter linker errors similar to the following:
 84>
 85> ```bash
 86> error: linking with `cc` failed: exit status: 1 ...
 87> = note: /usr/bin/ld: /tmp/rustcISMaod/libaws_lc_sys-79f08eb6d32e546e.rlib(f8e4fd781484bd36-bcm.o): in function `aws_lc_0_25_0_handle_cpu_env':
 88>           /aws-lc/crypto/fipsmodule/cpucap/cpu_intel.c:(.text.aws_lc_0_25_0_handle_cpu_env+0x63): undefined reference to `__isoc23_sscanf'
 89>           /usr/bin/ld: /tmp/rustcISMaod/libaws_lc_sys-79f08eb6d32e546e.rlib(f8e4fd781484bd36-bcm.o): in function `pkey_rsa_ctrl_str':
 90>           /aws-lc/crypto/fipsmodule/evp/p_rsa.c:741:(.text.pkey_rsa_ctrl_str+0x20d): undefined reference to `__isoc23_strtol'
 91>           /usr/bin/ld: /aws-lc/crypto/fipsmodule/evp/p_rsa.c:752:(.text.pkey_rsa_ctrl_str+0x258): undefined reference to `__isoc23_strtol'
 92>           collect2: error: ld returned 1 exit status
 93>   = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
 94>   = note: use the `-l` flag to specify native libraries to link
 95>   = 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)
 96> error: could not compile `remote_server` (bin "remote_server") due to 1 previous error
 97> ```
 98>
 99> **Cause**:
100> 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)
101> & [GCC-14 - build failure for FIPS module](https://github.com/aws/aws-lc/issues/2010)
102>
103> 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.
104>
105> **Workaround**:
106> 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`
107
108## Wayland & X11
109
110Zed 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=''`.
111
112## Notes for packaging Zed
113
114This section is for distribution maintainers packaging Zed.
115
116### Technical requirements
117
118Zed has two main binaries:
119
120- You will need to build `crates/cli` and make its binary available in `$PATH` with the name `zed`.
121- 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.
122- 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`).
123- 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.
124- For an example of a complete build script, see [script/bundle-linux](https://github.com/zed-industries/zed/blob/935cf542aebf55122ce6ed1c91d0fe8711970c82/script/bundle-linux).
125- 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."`.
126- 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.
127
128### Other things to note
129
130Zed moves quickly, and distribution maintainers often have different constraints and priorities. The points below describe current trade-offs:
131
132- Zed is a fast-moving project. We typically publish 2-3 builds per week to address reported issues and ship larger changes.
133- 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`.
134- 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).
135- 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).
136- 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).
137- 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).
138
139## Flatpak
140
141> Zed's current Flatpak integration exits the sandbox on startup. Workflows that rely on Flatpak's sandboxing may not work as expected.
142
143To build & install the Flatpak package locally follow the steps below:
144
1451. Install Flatpak for your distribution as outlined [here](https://flathub.org/setup).
1462. Run the `script/flatpak/deps` script to install the required dependencies.
1473. Run `script/flatpak/bundle-flatpak`.
1484. Now the package has been installed and has a bundle available at `target/release/{app-id}.flatpak`.
149
150## Memory profiling
151
152[`heaptrack`](https://github.com/KDE/heaptrack) is quite useful for diagnosing memory leaks. To install it:
153
154```sh
155$ sudo apt install heaptrack heaptrack-gui
156$ cargo install cargo-heaptrack
157```
158
159Then, to build and run Zed with the profiler attached:
160
161```sh
162$ cargo heaptrack -b zed
163```
164
165When 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.
166
167## Perf recording
168
169How to get a flamegraph with resolved symbols from a running Zed instance.
170Use this when Zed is using a lot of CPU. It is not useful for hangs.
171
172### During the incident
173
174- Find the PID (process ID) using:
175  `ps -eo size,pid,comm | grep zed | sort | head -n 1 | cut -d ' ' -f 2`
176  Or find the PID of `zed-editor` with the highest RAM usage in something
177  like htop/btop/top.
178
179- Install perf:
180  On Ubuntu (derivatives) run `sudo apt install linux-tools`.
181
182- Perf record:
183  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.
184
185- Make the output file user owned:
186  run `sudo chown $USER:$USER perf.data`
187
188- Get build info:
189  Run zed again and type `zed: about` in the command pallet to get the exact commit.
190
191The `perf.data` file can be sent to Zed together with the exact commit.
192
193### Later
194
195This can be done by Zed staff.
196
197- Build Zed with symbols:
198  Check out the commit found previously and modify `Cargo.toml`.
199  Apply the following diff, then make a release build.
200
201```diff
202[profile.release]
203-debug = "limited"
204+debug = "full"
205```
206
207- Add the symbols to the perf database:
208  `perf buildid-cache -v -a <path to release zed binary>`
209
210- Resolve the symbols from the db:
211  `perf inject -i perf.data -o perf_with_symbols.data`
212
213- Install flamegraph:
214  `cargo install cargo-flamegraph`
215
216- Render the flamegraph:
217  `flamegraph --perfdata perf_with_symbols.data`
218
219## Troubleshooting
220
221### Cargo errors claiming that a dependency is using unstable features
222
223Try `cargo clean` and `cargo build`.