1---
2title: REPL - Jupyter Kernels in Zed
3description: Run code interactively in Zed with built-in Jupyter kernel support. Execute Python, TypeScript, R, and more inline.
4---
5
6# REPL
7
8## Getting started
9
10Zed's built-in REPL uses [Jupyter kernels](https://docs.jupyter.org/en/latest/projects/kernels.html) so you can run code interactively in regular editor files.
11
12<figure style="width: 100%; margin: 0; overflow: hidden; border-top-left-radius: 2px; border-top-right-radius: 2px;">
13 <video loop controls playsinline>
14 <source
15 src="https://customer-snccc0j9v3kfzkif.cloudflarestream.com/aec66e79f23d6d1a0bee5e388a3f17cc/downloads/default.mp4"
16 type='video/webm; codecs="vp8.0, vorbis"'
17 />
18 <source
19 src="https://customer-snccc0j9v3kfzkif.cloudflarestream.com/aec66e79f23d6d1a0bee5e388a3f17cc/downloads/default.mp4"
20 type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'
21 />
22 <source
23 src="https://zed.dev/img/post/repl/typescript-deno-kernel-markdown.png"
24 type="image/png"
25 />
26 </video>
27</figure>
28
29## Installation
30
31Zed supports running code in multiple languages. To get started, you need to install a kernel for the language you want to use.
32
33**Currently supported languages:**
34
35- [Python (ipykernel)](#python)
36- [TypeScript (Deno)](#typescript-deno)
37- [R (Ark)](#r-ark)
38- [R (Xeus)](#r-xeus)
39- [Julia](#julia)
40- [Scala (Almond)](#scala)
41
42Once installed, you can start using the REPL in the respective language files, or other places those languages are supported, such as Markdown. If you recently added the kernels, run the `repl: refresh kernelspecs` command to make them available in the editor.
43
44## Using the REPL
45
46To start the REPL, open a file with the language you want to use and use the `repl: run` command (defaults to `ctrl-shift-enter` on macOS) to run a block, selection, or line. You can also click on the REPL icon in the toolbar.
47
48The `repl: run` command will be executed on your selection(s), and the result will be displayed below the selection.
49
50Outputs can be cleared with the `repl: clear outputs` command, or from the REPL menu in the toolbar.
51
52### Cell mode
53
54Zed supports [notebooks as scripts](https://jupytext.readthedocs.io/en/latest/formats-scripts.html) using the `# %%` cell separator in Python and `// %%` in TypeScript. This allows you to write code in a single file and run it as if it were a notebook, cell by cell.
55
56The `repl: run` command will run each block of code between the `# %%` markers as a separate cell.
57
58```python
59# %% Cell 1
60import time
61import numpy as np
62
63# %% Cell 2
64import matplotlib.pyplot as plt
65import matplotlib.pyplot as plt
66from matplotlib import style
67style.use('ggplot')
68```
69
70## Language specific instructions
71
72### Python {#python}
73
74#### Global environment
75
76<div class="warning">
77
78On macOS, your system Python will _not_ work. Either set up [pyenv](https://github.com/pyenv/pyenv?tab=readme-ov-file#installation) or use a virtual environment.
79
80</div>
81
82To setup your current Python to have an available kernel, run:
83
84```sh
85pip install ipykernel
86python -m ipykernel install --user
87```
88
89#### Conda Environment
90
91```sh
92source activate myenv
93conda install ipykernel
94python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
95```
96
97#### Virtualenv with pip
98
99```sh
100source activate myenv
101pip install ipykernel
102python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
103```
104
105### R (Ark Kernel) {#r-ark}
106
107Install [Ark](https://github.com/posit-dev/ark/releases) by downloading the release for your operating system. For example, for macOS just unpack `ark` binary and put it into `/usr/local/bin`. Then run:
108
109```sh
110ark --install
111```
112
113### R (Xeus Kernel) {#r-xeus}
114
115- Install [Xeus-R](https://github.com/jupyter-xeus/xeus-r)
116- Install the R Extension for Zed (search for `R` in Zed Extensions)
117
118<!--
119TBD: Improve R REPL (Ark Kernel) instructions
120-->
121
122### TypeScript: Deno {#typescript-deno}
123
124- [Install Deno](https://docs.deno.com/runtime/manual/getting_started/installation/) and then install the Deno jupyter kernel:
125
126```sh
127deno jupyter --install
128```
129
130<!--
131TBD: Improve R REPL (Ark Kernel) instructions
132-->
133
134### Julia
135
136- Download and install Julia from the [official website](https://julialang.org/downloads/).
137- Install the Julia Extension for Zed (search for `Julia` in Zed Extensions)
138
139<!--
140TBD: Improve Julia REPL instructions
141-->
142
143### Scala
144
145- [Install Scala](https://www.scala-lang.org/download/) with `cs setup` (Coursier):
146 - `brew install coursier/formulas/coursier && cs setup`
147- REPL (Almond) [setup instructions](https://almond.sh/docs/quick-start-install):
148 - `brew install --cask temurin` (Eclipse foundation official OpenJDK binaries)
149 - `brew install coursier/formulas/coursier && cs setup`
150 - `coursier launch --use-bootstrap almond -- --install`
151
152## Changing which kernel is used per language {#changing-kernels}
153
154Zed automatically detects available kernels and organizes them in the kernel picker:
155
156- **Recommended**: The Python environment matching your active toolchain (if detected)
157- **Python Environments**: Virtual environments (venv, virtualenv, Poetry, Pipenv, Conda, uv, etc.)
158- **Jupyter Kernels**: Installed Jupyter kernelspecs
159- **Remote Servers**: Connected remote Jupyter servers
160
161### Installing ipykernel
162
163Python environments appear in the picker even if ipykernel is not installed. Environments missing ipykernel are dimmed and labeled "ipykernel not installed." When you select one, Zed automatically runs `pip install ipykernel` in that environment and activates it once installation completes.
164
165### How Zed Recommends Kernels
166
167When you run code, Zed selects a kernel automatically:
168
1691. **Active toolchain match**: If a Python environment matches your active toolchain and has ipykernel, Zed uses it
1702. **First available Python env**: Otherwise, the first Python environment with ipykernel
1713. **Language-based fallback**: If no Python envs are ready, Zed picks a Jupyter kernel matching the code block's language
172
173You can override this by explicitly selecting a kernel from the picker.
174
175### Setting Default Kernels
176
177To configure a different default kernel for a language, you can assign a kernel for any supported language in your `settings.json`:
178
179```json [settings]
180{
181 "jupyter": {
182 "kernel_selections": {
183 "python": "conda-env",
184 "typescript": "deno",
185 "javascript": "deno",
186 "r": "ark"
187 }
188 }
189}
190```
191
192## Interactive Input
193
194When code execution requires user input (such as Python's `input()` function), the REPL displays an input prompt below the cell output.
195
196Type your response in the text field and press `Enter` to submit. The kernel receives your input and continues execution.
197
198For password inputs, characters appear masked with asterisks for security.
199
200If execution is interrupted while an input prompt is active, the prompt automatically clears when the kernel returns to idle state.
201
202## Debugging Kernelspecs
203
204Available kernels are shown via the `repl: sessions` command. To refresh the kernels you can run, use the `repl: refresh kernelspecs` command.
205
206If you have `jupyter` installed, you can run `jupyter kernelspec list` to see the available kernels.
207
208```sh
209$ jupyter kernelspec list
210Available kernels:
211 ark /Users/z/Library/Jupyter/kernels/ark
212 conda-base /Users/z/Library/Jupyter/kernels/conda-base
213 deno /Users/z/Library/Jupyter/kernels/deno
214 python-chatlab-dev /Users/z/Library/Jupyter/kernels/python-chatlab-dev
215 python3 /Users/z/Library/Jupyter/kernels/python3
216 ruby /Users/z/Library/Jupyter/kernels/ruby
217 rust /Users/z/Library/Jupyter/kernels/rust
218```
219
220> Note: Zed makes best effort usage of `sys.prefix` and `CONDA_PREFIX` to find kernels in Python environments. If you want explicitly control run `python -m ipykernel install --user --name myenv --display-name "Python (myenv)"` to install the kernel directly while in the environment.