Invoking Julia from the Terminal on MacOS

hi
happy to found julia after long time of hesitations in the choice of a language to make animated graphicals mathematics
now, i follow the instructions on
http://docs.julialang.org/en/stable/manual/getting-started/
i type “julia” in a temrinal windows of my mac os X.10.4
in the julia session i type : julia essai.jl
answer :
ERROR: UndefVarError: julia not defined
i guess that something is wrong with the fact that i installed julia throught a dmg file while the use of julia in the termonal shoul have maybe needed a mor "deep "installation with the sources etc ?
if anyone can help for this ultra-beggining question…
thanks !

2 Likes

To invoke Julia in the Terminal, you need to make sure that the julia command-line program is in your PATH. On MacOS, I usually do this by creating a link in /usr/local/bin:

sudo ln -s /Applications/Julia-0.5.app/Contents/Resources/julia/bin/julia /usr/local/bin/julia

(Assuming you have installed “Julia-0.5” into your Applications folder, as is typical.)

14 Likes

Also, the command in that doc is shell command used to run the script,not how you run a script once you’re in the julia REPL. To run a script in the REPL use include("script_path.jl")

1 Like

ok thank you both of you
both work now :
julia essai.jl from the terminal
include(“essai.jl”) from the julia prompt
i prefer the first method
now i can start
thanks

1 Like

Exactly what I needed. Thanks @stevengj

New UPDATE
I tried the command line above, by using the copy button on it. For some reason it would not work even after I edited it to the current version. I worked with the Apple Community and for some reason the same line with the current version now works:

sudo ln -s /Applications/Julia-1.8.app/Contents/Resources/julia/bin/julia /usr/local/bin/Julia

1 Like

Not sure I understand your second sentence, but in .zshrc I have:

alias j8="/Applications/Julia-1.8.app/Contents/Resources/julia/bin/julia"
alias j9="/Applications/Julia-1.9.app/Contents/Resources/julia/bin/julia"
alias j="/Users/rob/Projects/Julia/julia/julia"

for Julia 1.8, Julia 1.9 and Julia 1.10 (after building the nightly version).

How did you build the nightly version? I just installed the Homebrew version and it works from the command line (only).
Did you create the Alais, which I don’t think is a result of the path command line?? f

In a terminal, clone the repository once (while cd-ed to e.g. /Users/rob/Projects/Julia/ . To update, in the directory of the download, e.g. /Users/rob/Projects/Julia/julia, run git pull && make.

Editors such as VSCode, TextMate, SublimeText, etc. usually require some additional settings to point to above locations.

The alias-es I think were were created (copied) when Apple switched to using zshell. Or I might have done it as in my .cshrc there are many lines to start Julia projects, e.g.:

alias srs8="cd ~/.julia/dev/SR2StanPluto; j8 -i -e 'using Pkg; pkg\"activate .\"'"
alias srs9="cd ~/.julia/dev/SR2StanPluto; j9 -i -e 'using Pkg; pkg\"activate .\"'"
alias srs="cd ~/.julia/dev/SR2StanPluto; j -i -e 'using Pkg; pkg\"activate .\"'"

So the alias allows you to use the terminal. I take it that you just enter j8 or j9 in terminal to bring up Julia?

It was trying to use the path command line that I am not able to get to work now.
sudo ln -s /Applications/Julia-0.5.app/Contents/Resources/julia/bin/julia /usr/local/bin/Julia
but now that I installed it via Homebrew it does not matter. I have to call it from the terminal. All that I am doing are the little Academy Courses.

I expect Homebrew will make a julia command available to you from a location already in your path. That should suffice for usage from a Terminal.

It did. However we discussed it on the Apple Support Community. I do not know why the one that I copied here did not work. The folks there wrote it again, using the current version and it did work from the terminal. So I deleted the Homebrew installation, and reinstalled the Julia org application along with the command line that was verified to work as of this morning. And it is all working now. Oh well, I did need to update a lot of Homebrew dependencies for my QGIS and Ortho4XPlane anyway.