AlmaLinux Nimをインストールして使用する

AlmaLinux Nimをインストールして使用する

AlmaLinuxに開発言語の1つであるNimをインストールして使用するまでの手順を記述してます。

環境

  • OS  AlmaLinux 8.3

事前準備

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

sudo dnf install gcc

インストール

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

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

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

choosenim-init: Downloading choosenim-0.7.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.
n
    Answer: Downloading Nim 1.4.6 from nim-lang.org
[##################################################] 100.0% 0kb/s
 Extracting nim-1.4.6-linux_x64.tar.xz
   Building Nim 1.4.6
  Compiler: Already built
     Tools: 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.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を通します

export PATH=$HOME/.nimble/bin:$PATH

インストールが終わったので、バージョンを確認してみます。

nim -v

<出力結果>
Nim Compiler Version 1.4.6 [Linux: amd64]
Compiled at 2021-04-15
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 2b6b08032348939e5d355a6cb4faa0169306c17f
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.4.6/config/nim.cfg' [Conf]
Hint: used config file '/home/testuser/.choosenim/toolchains/nim-1.4.6/config/config.nims' [Conf]
....
Hint: gcc -c  -w -fmax-errors=3   -I/home/testuser/.choosenim/toolchains/nim-1.4.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.4.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.4.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: 22418 lines; 1.751s; 25.555MiB peakmem; Debug build; proj: /home/testuser/hello.nim; out: /home/testuser/hello [SuccessX]
Hint: /home/testuser/hello  [Exec]
hello, world

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

./hello

<出力結果>
hello, world