MIRACLE LINUX Nimをインストールする

MIRACLE LINUX Nimをインストールする

MIRACLE LINUXに、開発言語Nimをインストールするまでの手順です。

環境

  • OS MIRACLE LINUX release 8.4 (Peony)

事前準備

まず初めに、gccが必要なのでインストールしておきます。

$ sudo dnf install gcc

インストール

curlからインストールすることができます。

$ curl https://nim-lang.org/choosenim/init.sh -sSf | sh

gccがないとエラーになります。

     Error: No C compiler found. Nim compiler requires a C compiler.
        ... Install gcc using your favourite package manager.

情報を提供するか質問されるですが、「n」を選択してます。

choosenim-init: Downloading choosenim-0.8.2_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.4.8 from nim-lang.org
[##################################################] 100.0% 0kb/s
 Extracting nim-1.4.8-linux_x64.tar.xz
 Extracting nim-1.4.8-linux_x64.tar
   Building Nim 1.4.8
  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.4.8
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.4.8 [Linux: amd64]
Compiled at 2021-05-25
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 44e653a9314e1b8503f0fa4a8a34c3380b26fff3
active boot switches: -d:release

Hello Worldしてみる

「hello.nim」というファイルを作成します。

$ nano hello.nim

「hello.nim」に下記のコードを記述します。

stdout.write("hello, world")

コンパイルして実行します

$ nim compile --run hello.nim

Hello Worldが表示されていることが確認できます。

Hint: used config file '/home/testuser/.choosenim/toolchains/nim-1.4.8/config/nim.cfg' [Conf]
Hint: used config file '/home/testuser/.choosenim/toolchains/nim-1.4.8/config/config.nims' [Conf]
....
Hint: gcc -c  -w -fmax-errors=3   -I/home/testuser/.choosenim/toolchains/nim-1.4.8/lib -I/home/testuser/test -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.4.8/lib -I/home/testuser/test -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.4.8/lib -I/home/testuser/test -o /home/testuser/.cache/nim/hello_d/@mhello.nim.c.o /home/testuser/.cache/nim/hello_d/@mhello.nim.c [Exec]
Hint:  [Link]
Hint: 22422 lines; 1.189s; 25.629MiB peakmem; Debug build; proj: /home/testuser/test/hello.nim; out: /home/testuser/test/hello [SuccessX]
Hint: /home/testuser/test/hello  [Exec]

hello, world

「hello」というバイナリも作成されていることが確認できます。

実行すると「hello, world」が表示されます。

$ ./hello

<出力結果>
hello, world