Julia 的安裝,不管是使用編譯好的程序,還是自己從源代碼編譯,都很簡單。按照 這兒 的說明下載并安裝即可。
使用交互式會話(也記為 repl),是學習 Julia 最簡單的方法:
```
$ julia
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" to list help topics
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.3.0-prerelease+3690 (2014-06-16 05:11 UTC)
_/ |\__'_|_|_|\__'_| | Commit 1b73f04* (0 days old master)
|__/ | x86_64-apple-darwin13.1.0
julia> 1 + 2
3
julia> ans
3
```
輸入 `^D — ctrl` 鍵加 `d` 鍵,或者輸入 `quit()` ,可以退出交互式會話。交互式模式下, `julia` 會顯示一個橫幅,并提示用戶來輸入。一旦用戶輸入了完整的表達式,例如 `1 + 2` ,然后按回車,交互式會話就對表達式求值并返回這個值。如果輸入的表達式末尾有分號,就不會顯示它的值了。變量 `ans` 的值就是上一次計算的表達式的值,無論上一次是否被顯示。變量 `ans` 僅適用于交互式會話,不適用于以其它方式運行的 Julia 代碼。
如果想運行寫在源文件 `file.jl` 中的代碼,可以輸入命令 `include("file.jl")` 。
要在非交互式模式下運行代碼,你可以把它當做 Julia 命令行的第一個參數:
`$ julia script.jl arg1 arg2...`
如這個例子所示,julia 后面跟著的命令行參數,被認為是程序 script.jl 的命令行參數。這些參數使用全局變量 ARGS 來傳遞。使用 -e 選項,也可以在命令行設置 ARGS 參數。可如下操作,來打印傳遞的參數:
```
$ julia -e 'for x in ARGS; println(x); end' foo bar
foo
bar
```
也可以把代碼放在一個腳本中,然后運行:
```
$ echo 'for x in ARGS; println(x); end' > script.jl
$ julia script.jl foo bar
foo
bar
```
Julia 可以用 `-p` 或 `--machinefile` 選項來開啟并行模式。 `-p n` 會發起額外的 `n` 個工作進程,而 `--machinefile file` 會為文件 `file` 的每一行發起一個工作進程。 `file` 定義的機器,必須要能經由無密碼的 `ssh` 訪問,且每個機器上的 Julia 安裝的位置應完全相同,每個機器的定義為
`[user@]host[:port] [bind_addr]` 。 `user` defaults to current user, `port` to the standard ssh port. Optionally, in case of multi-homed hosts, `bind_addr` may be used to explicitly specify an interface.
如果你想讓 Julia 在啟動時運行一些代碼,可以將代碼放入
```
~/.juliarc.jl :
$ echo 'println("Greetings! 你好! ??????")' > ~/.juliarc.jl
$ julia
Greetings! 你好! ??????
...
```
運行 Julia 有各種可選項:
```
julia [options] [program] [args...]
-v, --version Display version information
-h, --help Print this message
-q, --quiet Quiet startup without banner
-H, --home <dir> Set location of julia executable
-e, --eval <expr> Evaluate <expr>
-E, --print <expr> Evaluate and show <expr>
-P, --post-boot <expr> Evaluate <expr> right after boot
-L, --load <file> Load <file> right after boot on all processors
-J, --sysimage <file> Start up with the given system image file
-p <n> Run n local processes
--machinefile <file> Run processes on hosts listed in <file>
-i Force isinteractive() to be true
--no-history-file Don't load or save history
-f, --no-startup Don't load ~/.juliarc.jl
-F Load ~/.juliarc.jl, then handle remaining inputs
--color={yes|no} Enable or disable color text
--code-coverage Count executions of source lines
--check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)
--int-literals={32|64} Select integer literal size independent of platform
```
### 資源
除了本手冊,還有一些其它的資源:
* [Julia 和 IJulia 使用說明](http://math.mit.edu/~stevenj/Julia-cheatsheet.pdf)
* [速學 Julia](http://learnxinyminutes.com/docs/julia/)
* [MIT 講師 Homer Reid 數值分析課的教程](http://homerreid.dyndns.org/teaching/18.330/JuliaProgramming.shtml)
* [介紹 julia 的演講](https://raw.githubusercontent.com/ViralBShah/julia-presentations/master/Fifth-Elephant-2013/Fifth-Elephant-2013.pdf)
* [來自 MIT 的 Julia 視頻教程](http://julialang.org/blog/2013/03/julia-tutorial-MIT/)
* [Forio 的 Julia 教程](http://forio.com/labs/julia-studio/tutorials/)