Ubuntu 22.04 LTSにプログラミング言語nimをインストールする方法

環境
OSバージョンの確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"
# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"

nimのインストール手順
1.依存パッケージをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo apt install curl build-essential
# sudo apt install curl build-essential
# sudo apt install curl build-essential

2.curlコマンドでnimをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# curl https://nim-lang.org/choosenim/init.sh -sSf | sh
choosenim-init: Downloading choosenim-0.8.2_linux_amd64
Info: Version 1.6.6 already selected
choosenim-init: ChooseNim installed in /root/.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=/root/.nimble/bin:$PATH
# curl https://nim-lang.org/choosenim/init.sh -sSf | sh choosenim-init: Downloading choosenim-0.8.2_linux_amd64 Info: Version 1.6.6 already selected choosenim-init: ChooseNim installed in /root/.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=/root/.nimble/bin:$PATH
# curl https://nim-lang.org/choosenim/init.sh -sSf | sh
choosenim-init: Downloading choosenim-0.8.2_linux_amd64
Info: Version 1.6.6 already selected
choosenim-init: ChooseNim installed in /root/.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=/root/.nimble/bin:$PATH

3.PATHを設定します
# nano ~/.profile
追記

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
export PATH=/root/.nimble/bin:$PATH
export PATH=/root/.nimble/bin:$PATH
export PATH=/root/.nimble/bin:$PATH

設定を反映します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# source ~/.profile
# source ~/.profile
# source ~/.profile

4.nimバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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
# 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
# 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

5.動作確認
# nano test.nim
以下の内容を編集します
echo “study skill become smart hello world"

「test.nim」をコンパイルします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# nim c test.nim
Hint: used config file '/root/.choosenim/toolchains/nim-1.6.6/config/nim.cfg' [Conf]
Hint: used config file '/root/.choosenim/toolchains/nim-1.6.6/config/config.nims' [Conf]
.........................................................
CC: stdlib_digitsutils.nim
CC: stdlib_dollars.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: test.nim
Hint: [Link]
Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
26670 lines; 4.108s; 31.578MiB peakmem; proj: /root/test.nim; out: /root/test [SuccessX]
# nim c test.nim Hint: used config file '/root/.choosenim/toolchains/nim-1.6.6/config/nim.cfg' [Conf] Hint: used config file '/root/.choosenim/toolchains/nim-1.6.6/config/config.nims' [Conf] ......................................................... CC: stdlib_digitsutils.nim CC: stdlib_dollars.nim CC: stdlib_io.nim CC: stdlib_system.nim CC: test.nim Hint: [Link] Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code) 26670 lines; 4.108s; 31.578MiB peakmem; proj: /root/test.nim; out: /root/test [SuccessX]
# nim c test.nim
Hint: used config file '/root/.choosenim/toolchains/nim-1.6.6/config/nim.cfg' [Conf]
Hint: used config file '/root/.choosenim/toolchains/nim-1.6.6/config/config.nims' [Conf]
.........................................................
CC: stdlib_digitsutils.nim
CC: stdlib_dollars.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: test.nim
Hint: [Link]
Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
26670 lines; 4.108s; 31.578MiB peakmem; proj: /root/test.nim; out: /root/test [SuccessX]

コンパイルしたファイルを実行します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# ./test
study skill become smart hello world
# ./test study skill become smart hello world
# ./test
study skill become smart hello world

 

Ubuntu 22.04

Posted by arkgame