M1 and Julia Language

JuliaLang on M1 chip – it works! New install and get started as an absolute beginner.

JuliaLang on M1 chip … it works!

A few weeks ago, my old Lenovo ThinkPad gave up. I was in the middle of the exam period for the Winter 2021 semester. So I had no choice but to replace it ASAP. For a long time, I wanted to purchase a MacBook. Now it was the time. I got a MacBook Pro 512 GB, 16 GB RAM, Apple M1 chip machine in space gray.

This week I am starting my summer student research internship. As previously announced, I’ll be working on the artificial spin ice project with one of the graduate students in our physics department. The research is purely computational, and all code is primarily written in Julia Language (Julia(me) working in Julia, LOL ).

The first step is obviously to install and get to know the necessary software for working in JuliaLang. If you are interested to know the details on what I’ll be using to write the scripts and how the specific software is installed on an M1 chip MacBook Pro, keep reading. We will be using the macOS terminal extensively. I am an absolute beginner when it comes to using the terminal, so please do not be afraid; it won’t be too complicated.

The first step is to install Julia. Go to https://julialang.org/ and download and install the latest version. It is still an Intel app, not Universal (see the pics for the difference). So, technically, without some help from Rosetta translating layer, which translates an Intel app to use with Apple silicon, it would not work. Big Sur macOS does not come pre-installed with Rosetta (or Rosetta 2). But as soon as you attempt to run any Intel app, it will automatically install. This happens very fast, so you might not even notice that it did. I did not realize this until I double-checked if Julia 1.6 is still an Intel application. Indeed it was, but it has no issues running on my Mac, which means Rosetta is doing its job. Note that Visual Studio Code is now a universal app, meaning it has been updated to support M1 natively.

Once I installed Julia, It was time to decide which text editor or IDE to use to write my scripts. There are several choices, as I learned.

  • The Julia REPL
  • Jupiter notebook
  • Pluto notebook
  • VS Studio Code with the Julia extension
  • Atom editor with Juno extension
  • PyCharm with Julia extension
  • Any other text editor of your choice (Vim, Sublime Text, Emacs, etc.)

To keep things easy, for now, I decided to work with Julia using either Pluto interactive notebooks or VS Code with Julia extension, depending on the project. I am going to go over the installation of both options in detail in this post.

Julia REPL and Pluto

Julia REPL is the full-featured interactive command-line (read-eval-print loop) you get when installing Julia. This is how the Julia shell looks like.

You can either use this shell by clicking on the Julia icon julialang to start working on your scripts or use the macOS terminal to invoke Julia REPL by simply typing the command julia. For the latter option to work, you first need to add Julia executable to PATH (which might be confusing if you are new to working with the terminal).

Adding Julia to PATH was a bit tricky, but I eventually figured it out. Here is how.

I opened the terminal and then opened the .zshrc file containing my zsh shell customization by typing (more about the .zshrc in a separate post soon):

nano ~/.zshrc

This file is normally hidden. You can’t see it in the Finder, unless you make it visible by clicking cmd+shift+. . With this command, it opens within the shell, and you can make edits to it. I added Julia to the PATH by simply pasting the following into the .zshrc file:

PATH="/Applications/Julia-1.6.app/Contents/Resources/julia/bin/:${PATH}"
export PATH

Then you press CTRL+X to save the changes, press Y to confirm the change, and hit ENTER to exit back to the shell. If you close the terminal and open it again, then type julia, it recognizes it as a command and enters the Julia REPL. If you would like to exit the REPL, type exit().

Once we have either the Julia REPL or julia command in the terminal working, we can use it directly or open either the Jupyter or Pluto interactive notebook.

We first need to add Pluto so we can use it in the shell. You need to switch from julia mode to package mode first by typing “]” in the terminal after the julia> prompt. And then we type:

pkg> add Pluto

After Pluto has been installed, we can exit the package mode or close the terminal and open it again and type:

julia> using Pluto
julia> Pluto.run()

to run Pluto and open the interactive notebook session like the one shown below.

Julia with VS Code extension

I also like the option to have an IDE to be able to work on my scripts. I chose VS Code since it has a nice extension for JuliaLang, and it also integrates with Git nicely. I recently attended the workshop on using Git for version control and would like to use this option extensively.

I first installed the Visual Studio Code by downloading it from https://code.visualstudio.com/. Then I opened the extensions option:

and searched for the keyword julia. This gives quite a few extensions to choose from related to Julia. Choose the very first one:

Now we are ready to learn some Julia syntax and explore its packages and libraries. I am very excited to share my learning journey with you. If you have anything specific questions in mind that you would like me to cover in future posts or videos (or both), please leave your comments below.

Cheers,

Julia

Sign up to receive awesome content in your inbox, every month.

We don’t spam! Read our privacy policy for more info.

Scroll to Top
%d bloggers like this: