By: Steven Whitaker
Re-posted from: https://glcs.hashnode.dev/install-julia-and-vscode
Julia is a relatively new,free, and open-source programming language.It has a syntaxsimilar to that of other popular programming languagessuch as MATLAB and Python,but it boasts being able to achieve C-like speeds.
One popular IDE to use with Juliais Visual Studio Code,or VS Code.
In this post,we will learn how to install Julia and VS Code.We will also learn how to configure VS Codeto get it to work with Julia.
The instructions for installing Julia and VS Codevary by operating system.Please use the table of contentsto jump to the instructionsthat are relevant to you.Note that the instructions for configuring VS Codeare the same for all operating systems.
Windows
Installing Julia
- Go to https://julialang.org/downloads.
-
In the table under the heading”Current stable release”,go to the row labeled “Windows”and click the “64-bit (installer)” link.(Of course, click the 32-bit linkif you have a 32-bit machine.)
(See Installing a Specific Julia Versionfor details on installing an older Julia version.)
- Run the installer.
-
Choose where to install Julia.(The default location works wellunless you have a specific needto install Julia somewhere else.)Then click “Next”.
-
Specify some additional options.
- “Create a Desktop shortcut”:Allows you to run Juliaby clicking the shortcuton your Desktop.
- “Create a Start Menu entry”:Allows you to pin Julia to your Start Menu.Also allows you to easily search for Juliafrom the Start Menu.
- “Add Julia to PATH”:(Recommended)Allows you to run Juliafrom the command linewithout specifying the full pathto the Julia executable.Also enables easier integrationwith VS Code.
Then click “Next”.
-
Installation is complete!Click “Finish” to exit the installer.
Running Julia
There are a few different waysto run Julia on Windows.
-
If you created a Desktop shortcut,you can double-click the shortcutto start Julia.
-
If you created a Start Menu entry,you can run Julia from the Start Menu.First search for “julia”.
And then click on the appropriate resultto start Julia.
- You can also run Juliafrom the command line(Command Prompt or PowerShell).If Julia was added to PATH,you can run
C:\Users\user> julia
Otherwise,you can specify the full (or relative) path.
C:\Users\user> .\AppData\Local\Programs\Julia-1.9.3\bin\julia.exe
After starting Juliayou will be greeted witha fresh Julia prompt.
Now you know how to install and run Julia on Windows!
Installing VS Code
- Go to https://code.visualstudio.com.
-
Click “Download for Windows”.
- Run the installer.
-
Click “I accept the agreement”and then click “Next”.
-
Choose where to install VS Code.(The default location works wellunless you have a specific needto install VS Code somewhere else.)Then click “Next”.
-
Specify the Start Menu folder for VS Code.(The default folder is fine.)Then click “Next”.
-
Specify additional options if desired.(The defaults are fine,but if you want a Desktop shortcutbe sure to select that option.)Then click “Next”.
-
Click “Install”.
-
Installation is complete!Click “Finish” to exit the installer.
Running VS Code
You can run VS Codeusing any of the methods described abovefor running Julia:
-
using the Desktop shortcut.
-
using the Start Menu.
- using the command line.
C:\Users\user> code
Now you know how to install and run VS Code on Windows!
Jump to Configuring VS Code for Juliato learn how to configure VS Code.
macOS
Installing Julia
- Go to https://julialang.org/downloads.
-
In the table under the heading”Current stable release”,go to the rows labeled “MacOS”and click the “64-bit (.dmg)” link for either Apple Siliconor the Intel or Rosetta link for older machines or special scenarios.
(See Installing a Specific Julia Versionfor details on installing an older Julia version.)
-
Open the downloads folder and double-click on the Julia Disk Image you just downloaded.
-
In the new window, drag Julia into the Applications folder.
-
Allow Julia to be copied with your credentials or Touch ID.
-
Eject the disk image, either with the eject buttonor with right-click and selecting “Eject”.
-
We recommend you follow these final instructionsto make it easier to open Julia on your Mac.Open a new terminal window and follow these instructions:
sudo mkdir -p /usr/local/binsudo rm -f /usr/local/bin/juliasudo ln -s /Applications/Julia-1.9.app/Contents/Resources/julia/bin/julia /usr/local/bin/julia
Running Julia
You can start Julia through your normal means of opening applicationsor through typing julia
into your terminal (if you did the last step above).See Apple’s support if you need help.
After starting Juliayou will be greeted witha fresh Julia prompt.
Now you know how to install and run Julia on macOS!
Installing VS Code
- Go to https://code.visualstudio.com.
-
Click “Download Mac Universal”.
-
Open the downloads folder and drag VSCode into the Applications folder.
-
Allow VSCode to be moved with your credentials or Touch ID.
You can start VS Code through your normal means of opening applications.
Now you know how to install and run VS Code on macOS!
Jump to Configuring VS Code for Juliato learn how to configure VS Code.
Linux
Installing Julia
- Go to https://julialang.org/downloads.
-
In the table under the heading”Current stable release”,go to the row labeled “Generic Linux on x86″and click the “64-bit (glibc)” link.(This link should work for most Linux systems.If you have a different computer architecture,you probably already know to choose a different download link.)
(See Installing a Specific Julia Versionfor details on installing an older Julia version.)
- Open a terminaland navigate to the directorywhere you want to install Julia.In this post,we will install Juliain
~/programs/julia/
.(Note that everything up to and including the$
is the terminal prompt,so the actual command to runis everything after the$
.)~$ mkdir -p ~/programs/julia~$ cd ~/programs/julia
- Move the downloaded archiveto the current directory.
~/programs/julia$ mv ~/Downloads/julia-1.9.3-linux-x86_64.tar.gz .
- Unarchive the file.
~/programs/julia$ tar xzf julia-1.9.3-linux-x86_64.tar.gz
- Add Julia to your PATHby adding the followingto your
.bashrc
or.zshrc
file.(Remember to change/home/user/programs/julia
to the directory where you installed Julia.)export PATH="$PATH:/home/user/programs/julia/julia-1.9.3/bin"
(Restart the terminal to actually update the PATH.)
Julia is now installed!
Running Julia
You can run Julia from the command line.
$ ~/programs/julia/julia-1.9.3/bin/julia
Or, if you added Julia to your PATH:
$ julia
After starting Juliayou will be greeted witha fresh Julia prompt.
Now you know how to install and run Julia on Linux!
Installing VS Code
The following steps were testedon a computer running Ubuntu.They should work as writtenfor any Debian-based Linux distribution,but modifications may be necessaryfor other Linux distributions.Note that you will need admin privilegesfor one of the steps below.
- Go to https://code.visualstudio.com.
-
Click ” .deb”.
- (Requires admin privileges)Either open your file managerand double-click the downloaded file,or install VS Codevia the command line.(Remember to change the file path/name as needed.)
$ sudo dpkg -i /home/user/Downloads/code_1.81.1-1691620686_amd64.deb
VS Code is now installed!
Running VS Code
You can run VS Code from the command line.
$ code
Now you know how to install and run VS Code on Linux!
Jump to Configuring VS Code for Juliato learn how to configure VS Code.
Installing a Specific Julia Version
If you need a specific version of Julia,you can navigate to the older releases pageand find the appropriate installerfor the version you need.For example,to install Julia 1.0.5 on Windows,you would find “v1.0.5” on the left columnand then click on the download linkto download the installer.
Otherwise,the installation instructionsshould be basically the same.
Configuring VS Code for Julia
After starting VS Codefor the first timeyou will be greeted with”Get Started with VS Code”.
Feel free to walk through the options,but for this postwe will ignore themand just click “< Welcome”on the top left of the window.That brings us to the welcome page.
We need to install the Julia extension for VS Code.
-
Click on the extensions button.
-
Search for “julia”.Click “install” on the Julia extension.
Now we need to make surethe Julia extension knows where Julia is installed.If you added Julia to PATH,this step can be skipped.However,if you get errors trying to run Julia in VS Codeor if you find the wrong Julia version is being used(if you have multiple versions installed),you can follow these steps.
-
Open the Julia extension settingsby clicking the settings icon.Click “Extension Settings”.
-
Search for “executable path”.Then type the path to the Julia executablein the “Julia: Executable Path” extension setting.
Now VS Code is ready for Julia development!
Developing Julia Code in VS Code
-
Click the file icon in the top leftto open the Explorer pane.Then click “Open Folder”.
- Navigate to a folder(or create one)where your Julia code will be saved.In this post,we created a folder called
Julia
. -
Click the “New File” buttonnext to the folder in the Explorer pane.Then type a name for the filewhere you will write Julia code.It should have a
.jl
extension.In this post,we created a file calledscript.jl
.VS Code will now open a new tabwith a blank fileready for us to edit.
- Add the following code to your fileand then save it.
println("Hello, World!")
-
To run the code,place your cursor on the line of code to executeand then press
Shift+Enter
.This command will start a Julia session(if one has not already been started)and then run the code.(The very first time you run codemay take a little whilebecause packages need to precompile.) -
Now add more lines of code.
function plus1(x) x + 1enda = 3b = plus1(a)b == a + 1
-
To run all the code in the file,open the command palettewith
Ctrl+Shift+P
and search for”Julia: Execute active file in REPL”.Highlight the command and pressEnter
.Note that two lines of outputwere added to the REPL:the
println
statementand the value ofb == a + 1
(the last line that was executed). -
Now that some code has run,we can look at the Julia paneon the leftand see the variables and function we definedin the “Workspace” tab.
-
We can also use the REPL directly.
And now you know how to write and run Julia codein VS Code!
If you would like to see more tips and tricksfor how to use Julia in VS Code,be sure to comment below!
Summary
In this post,we learned how to install Juliaand VS Codeon different operating systems.We also learned how to configure VS Codefor developing Julia code.
Once you have installed Julia,move on to thenext post to learn about variables and functions!Or,feel free to take a lookat our other Julia tutorial posts!