# External Julia REPL in VSCode

**URL:** <https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745>\
**Category:** VS Code\
**Created:** [November 25, 2020, 12:36pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745 "2020-11-25T12:36:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 25, 2020, 12:36pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/1 "2020-11-25T12:36:16Z")

</div>

Someone recently asked in Slack if it was possible to to launch the Julia REPL process in a separate window (i.e. a separate terminal) and have that hooked up with the Julia extension such that you can send code to it from the editor. This can be pretty useful, for example, if you have a second monitor where you want to keep the REPL and thus make it possible to maximize the editor window on the first monitor.

I figured out a way of doing it and just wanted to share this since it might be useful for others. It might have to be tailored a bit for other terminals/systems, so perhaps that can be crowd sourced in the comments. I used Ubuntu with the default GNOME Terminal.

Anyway, here is what I did; Create a wrapper script (e.g. `julia-wrapper-external-repl`) with the following content:

```julia
#!/bin/bash

# Wrapper script for launching an external Julia REPL in 
# VSCode using the Julia extension.
# Configured for Linux (Ubuntu) with the default GNOME Terminal

## Path to julia executable
JULIA=/opt/julia/julia-1.5/bin/julia

if [-z "${JULIA_LANGUAGESERVER}"]; then
    ## User-process; launch a new terminal window and exec julia
    cmd="${JULIA} "$@""
    exec gnome-terminal --disable-factory -e "$cmd"
else
    ## Language server process; exec julia
    exec ${JULIA} "$@"
fi

```

and make it executable. Next, point the `Julia: Executable Path` extension setting to this script and voilà!

This works by inspecting the `JULIA_LANGUAGESERVER` variable, which is only set when the Julia extension is launching its Language Server process. If this variable is empty we launch an external terminal window and start julia in it, and if it is set we `exec` normally.

Hope some of you find it useful!

---

<div class="post-metadata">

**Author:** ![Steven\_Varga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steven_varga/32/3529_2.png) [@Steven\_Varga](https://discourse.julialang.org/u/Steven_Varga)\
**Post date:** [December 22, 2020, 5:26pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/2 "2020-12-22T17:26:50Z")

</div>

Thank you for this great work, **good idea** indeed! – I was looking for something similar to find out why vscode-julia doesn’t work with intel-mkl compiled julia binary – which seems to be rooted in how MKL manages shared objects.

Used your idea to preload/source the Intel MKL scripts, below is the modified copy. The first julia start flashes a terminal up **super fast** and fails (can’t read error, too fast for my eyes…), then the second try, same session, starts the terminal with julia (stays on screen, fully functional prompt) then each line is reflected in the **vscode** terminal (not in the julia one) and nothing else happens.

**Is there a way** to slow/pause the startup process – so I could read the error message? or an idea how to capture/redirect error message – perhaps with [tmux](https://github.com/tmux/tmux/wiki)?

best wishes: steven

```julia
#!/bin/bash

# Wrapper script for launching an external Julia REPL in
# VSCode using the Julia extension.
# Configured for Linux (Ubuntu) with the default GNOME Terminal

source /opt/intel/bin/compilervars.sh intel64
source /opt/intel/parallel_studio_xe_2020/bin/psxevars.sh &> /dev/null
## Path to julia executable
JULIA=/usr/local/bin/julia

if [-z "${JULIA_LANGUAGESERVER}"]; then
    ## User-process; launch a new terminal window and exec julia
    cmd="${JULIA} "$@""
    exec mate-terminal --disable-factory -e "$cmd"
else
    ## Language server process; exec julia
    exec ${JULIA} "$@"
fi

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [December 22, 2020, 5:31pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/3 "2020-12-22T17:31:38Z")

</div>

The error is just us starting (what we think is) Julia once to get version info and verify at actually works.

> [@Steven\_Varga](#):
>
> then the second try, same session, starts the terminal with julia (stays on screen, fully functional prompt) then each line is reflected in the **vscode** terminal (not in the julia one) and nothing else happens.

Don’t try to evaluate code with `Ctrl-Enter` (default), use `Alt-Enter` instead. The former relies on the VSCode APIs to insert text into the REPL, while the latter sends the code you want to execute over a pipe.

---

<div class="post-metadata">

**Author:** ![musm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/musm/32/3675_2.png) [@musm](https://discourse.julialang.org/u/musm)\
**Post date:** [December 23, 2020, 5:54am UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/4 "2020-12-23T05:54:38Z")

</div>

Has anyone managed to get this to work on Windows.

I have tried something like

```julia
@echo off
set JULIA=C:\Tools\Julia\julia-latest\bin\julia.exe
setlocal enableDelayedExpansion

IF "%JULIA_LANGUAGESERVER%"=="" (start wt %JULIA% %*) ELSE (start %JULIA% %*)

```

---

<div class="post-metadata">

**Author:** ![darsnack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darsnack/32/10144_2.png) [@darsnack](https://discourse.julialang.org/u/darsnack)\
**Post date:** [December 28, 2020, 6:30pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/5 "2020-12-28T18:30:41Z")

</div>

I am trying to get this working on my system, and it appears as though `JULIA_LANGUAGESERVER` is not reliably set. In my wrapper, the first thing I do is `printenv > /Users/darsnack/julialog`. Sometimes, the log is full of environment variables, and it is clear that the process is being launch under my user with my full shell environment + rc (`zsh`). Notably, `JULIA_LANGUAGESERVER` is unset, and things try to launch in a new terminal window with failed results. Other times, the log is only a few lines long, but `JULIA_LANGUAGESERVER` is set and everything starts up fine.

Weirdly, I can open up two totally separate repos _at the same time_ in separate VS Code windows, and I get different results for each one.

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [December 28, 2020, 6:51pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/6 "2020-12-28T18:51:22Z")

</div>

I use WSL 2 with the Vscode extension. I’d love it if someone can make it work for WSL2. Technically the julia processes are being launched within the Linux OS, but the terminal is Windows Terminal, so I don’t know whether I need a bash script or a cmd script.

---

<div class="post-metadata">

**Author:** ![donquicote](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@donquicote](https://discourse.julialang.org/u/donquicote)\
**Post date:** [February 16, 2021, 9:13pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/7 "2021-02-16T21:13:58Z")

</div>

Any update on making this work on Windows?

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [June 11, 2021, 5:09pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/8 "2021-06-11T17:09:42Z")

</div>

This is so smart! I can now use remote development with julia-vscode on MKL+1.7 and still have a fully functional Julia Language Server! Thanks a lot.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 11, 2021, 8:36pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/9 "2021-06-11T20:36:04Z")

</div>

I think the latest version of the Julia extension has native support for this so this hack isn’t necessary anymore IIUC.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [June 11, 2021, 10:34pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/10 "2021-06-11T22:34:39Z")

</div>

Oh, really? It was @pfitzseb himself (thanks!) that pointed me to this idea of yours on Slack. I was asking him how one could use julia 1.7 with the current language server, that only works under 1.6 AFAIU, and he mentioned this. I’m using v1.2.3 of the julia-vscode extension. Perhaps you mean the master version currently in development?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 11, 2021, 10:40pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/11 "2021-06-11T22:40:13Z")

</div>

Ah sorry, I thought you were talking about an external REPL.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [June 11, 2021, 10:58pm UTC](https://discourse.julialang.org/t/external-julia-repl-in-vscode/50745/12 "2021-06-11T22:58:30Z")

</div>

My mistake, I didn’t specify the problem. Indeed, it would perhaps be nice to have two "executable path"s in the future, one for the language server and another for the runtime.
