Sublime Text and Julia IDE

Sublime Text and Julia IDE

March 1, 2024

Sometimes, I am asked how to set up a simple Julia IDE for people who are already using Sublime Text. It is simple in theory but many things can go wrong, so I thought this document could be useful.

I try to provide step by step instructions as much as possible. Feel free to email me if some of the steps were not as clear as you would have liked.

N.B.

  • There might be better ways to have a Julia IDE (see VSCode with LSP). I happen to like Sublime, it is simpler and faster than VSCode (but I am also an emacs person).
  • Also note that the same thing would apply for R (just change a few paths here and there).

This guide was written on 2024-03-xx for Sublime Text 4 and Julia 1.10.1

1. Prerequisite #

The “required” software for this guide are: Julia, Sublime Text, and a Terminal application called iterm2.

First, I would recommend to install (optional but recommended) a nicer terminal application than the built-in macos terminal:

  • Download iterm2.

    • This is not strictly necessary but iterm2 has some nice feature that make it work nicely with the Sublime setup here. There are other good terminal applications for macos (e.g. kitty) but I am not as familiar with those.
    • Open the iterm2 application which should be in the application folder (note I will use the words iterm2 and the terminal interchangeably (technically they are not quite the same thing but it won’t matter).
  • Download Sublime Text 4 and follow the instructions to install.

  • Download julia and follow the instructions to install.

    • As I am writing this, you can use juliaup to install Julia by copying and pasting in your terminal the following: curl -fsSL https://install.julialang.org | sh This allows you to keep your version of Julia up to date (this might be a bad thing if you have old code and are not templating packages)
    • Or (simpler imho) download the latest current stable release and install it depending on your platform
      • For example for macos with Apple Silicon download the dmg and install it in your application folder

2. Getting julia to work! #

2.1 Basic installation #

If Julia is in your application folder, there are two ways to start a julia session.

  1. Double click on the julia icon: this opens the macos terminal application (not iterm2) and starts julia
  2. Open the terminal (I am assuming iterm2 from now on) and type or paste the path of the julia application binary.
    • For julia 1.10.1 the binary will likely at /Applications/Julia-1.10.app/Contents/Resources/julia/bin/julia
    • If you are working with version 1.XX (where XX is a different number) the path will likely be /Applications/Julia-1.XX.app/Contents/Resources/julia/bin/julia

2.2 Adding julia to your path #

Do you need it? #

If you have installed julia using juliaup (see section 1 above), the julia application was automatically added to your PATH.1 I believe this means the next step is not necessary. To see whether you should skip the next step type julia inside of iterm2. If julia opens, you are in business, skip 2.2 and go to section 3. If there is some error or julia does not open, follow the instructions in the next section 2.2.

Adding julia to the path #

Typing the full julia path can get annoying pretty quickly, so we will add the directory to the PATH for the terminal (technically for the shell). To make this permanent we are going to edit a special file which is read everytime you start your terminal.

On macos the file is .zshrc since the default shell is zsh; this is a configuration file. On other machine the file might be .bashrc if your default shell is bash.

To edit this file we need a text editor. Any will do; for example you could use textedit and enter the following at the terminal: open -a TextEdit ~/.zshrc This tells textedit to open the zsh configuration file which is located on your home directory under ~2 You could also use Sublime Text that you just opened; the following should work if it installed properly in the Applications folder: /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl ~/.zshrc

Now we need to edit this file by adding julia to the path. We can simply add this line:

export PATH=$PATH:/Applications/Julia-1.10.app/Contents/Resources/julia/bin

This concatenates your path with what was already in it ($PATH) and the directory where the julia binary is. If you are working with a version different than 1.10 then adjust the line for 1.XX as: export PATH=$PATH:/Applications/Julia-1.XX.app/Contents/Resources/julia/bin

Save the file. Close the window. Restart the terminal (iterm2). Now you should be able to start Julia in the terminal by typing julia from anywhere.

3. Getting Sublime Text to play nice with Julia #

Sublime text is an editor that relies on packages for added functionality. So next, we will download the necessary packages to get a setup that will let you work with Julia from sublime text.

3.1. Installing Sublime packages #

  • First install the package that can install other packages: that is package control. The instructions to install it are:

    1. Open the command palette (cmd+shift+p on macos)
    2. Type Install Package Control, press enter
  • Then install the Julia-sublime package similary:

    1. Open the command palette (cmd+shift+p on macos)
    2. Type Package Control: Install, press enter
    3. Then a dropdown menu will show and type Julia to search for the Julia package, type enter to install it.
  • Last install the SendCode package

    1. Open the command palette (cmd+shift+p on macos)
    2. Type Package Control: Install, press enter
    3. Then a dropdown menu will show and type SendCode to search for the SendCode package, type enter to install it.

3.2 Setting up Sublime packages #

  1. Settings of SendCode
    • Open the settings of sendcode: open the command palette (cmd+shift+p on macos), type SendCode settings, and enter
    • You should be dropped into a new window with two files (one on each side). Edit the one on the right which is the one with your personal settings (the one on the left has the general settings). Its name is SendCode.sublime-settings.
    • If you are working with iterm2 copy and paste the following:
{
  "auto_advance": true,
  "prog": "iterm",
  "julia":
  {
    "bracketed_paste_mode": true,
    "prog": "iterm",
  },
  "r":
  {
    "bracketed_paste_mode": true,
    "prog": "iterm",
  },
}
  1. Keybindings SendCode
    • Open the settings of sendcode: open the command palette (cmd+shift+p on macos), type SendCode key bindings, and enter
    • You should be dropped into a new window with two files (one on each side). Edit the one on the right which is the one with your personal settings (the one on the left has the general settings).
    • This time do not remove existing keybindings as they might be useful stuff.
    • You should add the following to make sure sending lines or highlighted content to be sent to iterm2.
 { "keys": ["super+enter"], "command": "send_code", 
   "context": [{ "key": "selector", "operator": "equal", "operand": "source" } ] },
 { "keys": ["ctrl+enter"], "command": "send_code", 
   "context": [{ "key": "selector", "operator": "equal", "operand": "source" } ] },
  • Feel free to change the key bindings for example if you want Cmd-s to send to iterm2 you would replace “super+enter” by “super+s”.

You should be good to go. Create a test.jl file. Open a terminal session and start Julia on the side. select 1+1 in sublime text and press Cmd+Enter at the same time. It should be sending to the terminal.


  1. Your path is essentially a set of places where the terminal looks for software. So if the directory of Julia gets added to the path, the terminal is aware of the Julia application and you can type directly $ julia↩︎

  2. ~ represents what is known as your home directory. The actual address is /Users/yourname/. You can find it by doing in the terminal: cd ~ to change directory to the home directory, and then pwd to print the directory you are currently in. ↩︎



Code
Julia, IDE