CentOS9 プログラム言語「Nim」をインストールする
CentOS9にプログラム言語の1つであるNimをインストールして使用するまでの手順を記述してます。
環境
- OS CentOS Stream release 9
事前準備
gccが必要なのでインストールしておきます。
$ sudo dnf install gcc
インストール
「curl」を使ってインストールします。
$ curl https://nim-lang.org/choosenim/init.sh -sSf | sh
インストール途中に、情報を提供するか質問されるですが、ここでは「n」を選択してます。
choosenim-init: Downloading choosenim-0.8.4_linux_amd64
Prompt: Can choosenim record and send anonymised telemetry data? [y/n]
... Anonymous aggregate user analytics allow us to prioritise
... fixes and features based on how, where and when people use Nim.
... For more details see: https://goo.gl/NzUEPf.
Answer: n
Downloading Nim 1.6.6 from nim-lang.org
[##################################################] 100.0% 0kb/s
Extracting nim-1.6.6-linux_x64.tar.xz
Extracting nim-1.6.6-linux_x64.tar
Building Nim 1.6.6
Compiler: Already built
Installed component 'nim'
Installed component 'nimble'
Installed component 'nimgrep'
Installed component 'nimpretty'
Installed component 'nimsuggest'
Installed component 'testament'
Installed component 'nim-gdb'
Switched to Nim 1.6.6
choosenim-init: ChooseNim installed in /home/testuser/.nimble/bin
choosenim-init: You must now ensure that the Nimble bin dir is in your PATH.
choosenim-init: Place the following line in the ~/.profile or ~/.bashrc file.
choosenim-init: export PATH=/home/testuser/.nimble/bin:$PATH
記述にあるとおりに「PATH」を通しておきます。
$ echo 'export PATH=$HOME/.nimble/bin:$PATH' >> ~/.bash_profile
反映させます。
$ exec $SHELL -l
バージョンを確認してみます。
$ nim -v
Nim Compiler Version 1.6.6 [Linux: amd64]
Compiled at 2022-05-05
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: 0565a70eab02122ce278b98181c7d1170870865c
active boot switches: -d:release
「Hello World」してみる
「hello.nim」という名前でファイルを作成して、
$ nano hello.nim
下記のコードを記述します。
stdout.write("hello, world")
コンパイルして実行します
$ nim compile --run hello.nim
Hello Worldが表示されていることが確認できます。
Hint: used config file '/home/testuser/.choosenim/toolchains/nim-1.6.6/config/nim.cfg' [Conf]
Hint: used config file '/home/testuser/.choosenim/toolchains/nim-1.6.6/config/config.nims' [Conf]
.........................................................
Hint: gcc -c -w -fmax-errors=3 -I/home/testuser/.choosenim/toolchains/nim-1.6.6/lib -I/home/testuser -o /home/testuser/.cache/nim/hello_d/stdlib_digitsutils.nim.c.o /home/testuser/.cache/nim/hello_d/stdlib_digitsutils.nim.c [Exec]
Hint: gcc -c -w -fmax-errors=3 -I/home/testuser/.choosenim/toolchains/nim-1.6.6/lib -I/home/testuser -o /home/testuser/.cache/nim/hello_d/stdlib_dollars.nim.c.o /home/testuser/.cache/nim/hello_d/stdlib_dollars.nim.c [Exec]
Hint: gcc -c -w -fmax-errors=3 -I/home/testuser/.choosenim/toolchains/nim-1.6.6/lib -I/home/testuser -o /home/testuser/.cache/nim/hello_d/stdlib_io.nim.c.o /home/testuser/.cache/nim/hello_d/stdlib_io.nim.c [Exec]
Hint: gcc -c -w -fmax-errors=3 -I/home/testuser/.choosenim/toolchains/nim-1.6.6/lib -I/home/testuser -o /home/testuser/.cache/nim/hello_d/stdlib_system.nim.c.o /home/testuser/.cache/nim/hello_d/stdlib_system.nim.c [Exec]
Hint: gcc -c -w -fmax-errors=3 -I/home/testuser/.choosenim/toolchains/nim-1.6.6/lib -I/home/testuser -o /home/testuser/.cache/nim/hello_d/@mhello.nim.c.o /home/testuser/.cache/nim/hello_d/@mhello.nim.c [Exec]
Hint: [Link]
Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
26670 lines; 1.651s; 31.602MiB peakmem; proj: /home/testuser/hello.nim; out: /home/testuser/hello [SuccessX]
Hint: /home/testuser/hello [Exec]
hello, world
helloというバイナリも作成されていることが確認できます。
$ ./hello
<出力結果>
hello, world
-
前の記事
mongoDB 結果を見やすく整形する 2022.10.01
-
次の記事
CentOS9 Anydeskをインストールする 2022.10.01
コメントを書く