Debian 11.2に静的型付V言語をインストールする

環境情報
# cat /etc/debian_version
11.2

インストール方法
1.必要なパッケージbuild-essentialをインストールします

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

2.gitをインストールします
# sudo apt install git
gitバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# git --version
git version 2.30.2
# git --version git version 2.30.2
# git --version
git version 2.30.2

3.V言語をダウンロードします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# mkdir -p /opt/vlang
# cd /opt/vlang
# git clone https://github.com/vlang/v
Cloning into 'v'...
remote: Enumerating objects: 107720, done.
remote: Total 107720 (delta 0), reused 0 (delta 0), pack-reused 107720
Receiving objects: 100% (107720/107720), 46.06 MiB | 3.99 MiB/s, done.
Resolving deltas: 100% (76847/76847), done.
# mkdir -p /opt/vlang # cd /opt/vlang # git clone https://github.com/vlang/v Cloning into 'v'... remote: Enumerating objects: 107720, done. remote: Total 107720 (delta 0), reused 0 (delta 0), pack-reused 107720 Receiving objects: 100% (107720/107720), 46.06 MiB | 3.99 MiB/s, done. Resolving deltas: 100% (76847/76847), done.
# mkdir -p /opt/vlang
# cd /opt/vlang
# git clone https://github.com/vlang/v
Cloning into 'v'...
remote: Enumerating objects: 107720, done.
remote: Total 107720 (delta 0), reused 0 (delta 0), pack-reused 107720
Receiving objects: 100% (107720/107720), 46.06 MiB | 3.99 MiB/s, done.
Resolving deltas: 100% (76847/76847), done.

4.V言語をインストールします
vディレクトリに移動してビルドします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cd v
# make
make fresh_vc
make[1]: Entering directory '/opt/vlang/v'
rm -rf ./vc
git clone --depth 1 --quiet --single-branch https://github.com/vlang/vc ./vc
make[1]: Leaving directory '/opt/vlang/v'
cd ./vc && git clean -xf && git pull --quiet
make fresh_tcc
make[1]: Entering directory '/opt/vlang/v'
rm -rf ./thirdparty/tcc
git clone --depth 1 --quiet --single-branch --branch thirdparty-linux-amd64 https://github.com/vlang/tccbin ./thirdparty/tcc
make[1]: Leaving directory '/opt/vlang/v'
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc -std=gnu99 -w -I ./thirdparty/stdatomic/nix -o v1.exe ./vc/v.c -lm -lpthread
./v1.exe -no-parallel -o v2.exe cmd/v
./v2.exe -o ./v cmd/v
rm -rf v1.exe v2.exe
V has been successfully built
V 0.2.4 68452cf
# cd v # make make fresh_vc make[1]: Entering directory '/opt/vlang/v' rm -rf ./vc git clone --depth 1 --quiet --single-branch https://github.com/vlang/vc ./vc make[1]: Leaving directory '/opt/vlang/v' cd ./vc && git clean -xf && git pull --quiet make fresh_tcc make[1]: Entering directory '/opt/vlang/v' rm -rf ./thirdparty/tcc git clone --depth 1 --quiet --single-branch --branch thirdparty-linux-amd64 https://github.com/vlang/tccbin ./thirdparty/tcc make[1]: Leaving directory '/opt/vlang/v' cd ./thirdparty/tcc && git clean -xf && git pull --quiet cc -std=gnu99 -w -I ./thirdparty/stdatomic/nix -o v1.exe ./vc/v.c -lm -lpthread ./v1.exe -no-parallel -o v2.exe cmd/v ./v2.exe -o ./v cmd/v rm -rf v1.exe v2.exe V has been successfully built V 0.2.4 68452cf
# cd v
# make
make fresh_vc
make[1]: Entering directory '/opt/vlang/v'
rm -rf ./vc
git clone --depth 1 --quiet --single-branch https://github.com/vlang/vc ./vc
make[1]: Leaving directory '/opt/vlang/v'
cd ./vc && git clean -xf && git pull --quiet
make fresh_tcc
make[1]: Entering directory '/opt/vlang/v'
rm -rf ./thirdparty/tcc
git clone --depth 1 --quiet --single-branch --branch thirdparty-linux-amd64 https://github.com/vlang/tccbin ./thirdparty/tcc
make[1]: Leaving directory '/opt/vlang/v'
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc  -std=gnu99 -w -I ./thirdparty/stdatomic/nix -o v1.exe ./vc/v.c -lm -lpthread
./v1.exe -no-parallel -o v2.exe  cmd/v
./v2.exe -o ./v  cmd/v
rm -rf v1.exe v2.exe
V has been successfully built
V 0.2.4 68452cf

5.シンボリックリンクを作成します
vという実行可能ファイルが生成されます。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo ./v symlink
# sudo ./v symlink
# sudo ./v symlink

6.vコマンドを実行します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# v
Welcome to the V REPL (for help with V itself, type exit , then run v help ).
NB: the REPL is highly experimental. For best V experience, use a text editor,
save your code in a main.v file and execute: v run main.v
V 0.2.4 68452cf
Use Ctrl-C or exit to exit, or help to see other available commands
>>>
# v Welcome to the V REPL (for help with V itself, type exit , then run v help ). NB: the REPL is highly experimental. For best V experience, use a text editor, save your code in a main.v file and execute: v run main.v V 0.2.4 68452cf Use Ctrl-C or exit to exit, or help to see other available commands >>>
# v
Welcome to the V REPL (for help with V itself, type  exit , then run  v help ).
  NB: the REPL is highly experimental. For best V experience, use a text editor,
  save your code in a  main.v  file and execute:  v run main.v
V 0.2.4 68452cf
Use Ctrl-C or  exit  to exit, or  help  to see other available commands
>>>

テストプログラムを作成します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
>>> fn main() {
... println('test v language')
... }
出力結果
test v language
>>> fn main() { ... println('test v language') ... } 出力結果 test v language
>>> fn main() {
... println('test v language')
... }

出力結果
test v language

7.サンプルコードを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cd examples/
# v hello_world.v && ./hello_world
Hello, World!
# cd examples/ # v hello_world.v && ./hello_world Hello, World!
# cd examples/
# v hello_world.v && ./hello_world
Hello, World!

8.v言語をアップデートします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# v up
Updating V...
Current V version:
V 0.2.4 68452cf, timestamp: 2021-12-23 18:57:15 +0200
# v up Updating V... Current V version: V 0.2.4 68452cf, timestamp: 2021-12-23 18:57:15 +0200
# v up
Updating V...
Current V version:
V 0.2.4 68452cf, timestamp: 2021-12-23 18:57:15 +0200

 

Debian 11

Posted by arkgame