Getting Started

    The easiest way to learn and experiment with Julia is by starting an interactive session (also known as a read-eval-print loop or “REPL”) by double-clicking the Julia executable or running from the command line:

    To exit the interactive session, type CTRL-D (press the Control/^ key together with the d key), or type exit(). When run in interactive mode, julia displays a banner and prompts the user for input. Once the user has entered a complete expression, such as 1 + 2, and hits enter, the interactive session evaluates the expression and shows its value. If an expression is entered into an interactive session with a trailing semicolon, its value is not shown. The variable ans is bound to the value of the last evaluated expression whether it is shown or not. The ans variable is only bound in interactive sessions, not when Julia code is run in other ways.

    To evaluate expressions written in a source file file.jl, write include("file.jl").

    1. $ julia script.jl arg1 arg2...

    As the example implies, the following command-line arguments to julia are interpreted as command-line arguments to the program script.jl, passed in the global constant ARGS. The name of the script itself is passed in as the global PROGRAM_FILE. Note that ARGS is also set when a Julia expression is given using the -e option on the command line (see the julia help output below) but PROGRAM_FILE will be empty. For example, to just print the arguments given to a script, you could do this:

    Or you could put that code into a script and run it:

    1. $ echo 'println(PROGRAM_FILE); for x in ARGS; println(x); end' > script.jl
    2. script.jl
    3. foo
    4. bar

    The -- delimiter can be used to separate command-line arguments intended for the script file from arguments intended for Julia:

    If you have code that you want executed whenever Julia is run, you can put it in ~/.julia/config/startup.jl:

    1. $ julia
    2. Greetings! 你好! 안녕하세요?

    There are various ways to run Julia code and provide options, similar to those available for the perl and ruby programs:

    A curated list of useful learning resources to help new users get started can be found on the learning page of the main Julia web site.