プログラミング言語 Dart

作成日 : 2020-12-17
最終更新日 :

Dart とは

Dart とは、Google が開発したコンピュータ言語である。 JavaScript の代替を意図している。

インストール

普通なら Windows にインストールするのだろうが、 最近は WSL の Ubuntu にインストールができるかどうかを試している。 Dart Install Ubuntu としてみたら、次のページが見つかった:

http://dartsim.github.io/install_dart_on_ubuntu.html

ここを見てみた。 Supported Platforms によれば、 DART 6.8 supports Ubuntu 32 and 64 bit 16.04 (Xenial), 18.04 (Bionic), 18.10 (Cosmic), and 19.04 (Disco) systems. とある。20.04 はないのか?
ここの DART は、Dynamic Animation and Robotics Toolkit であり、 Google の作った言語ではない。なので、ここでやめればよかったのだが、 私はそのときそんなことを知らずに、この DART をインストールしてしまった。 以下は、その記録である。

私が DART の人柱となるしかないのか? Install DART using Ubuntu packages の項にしたがって試してみる。 なお、apt-get install は apt install に読み替える。

    $ sudo apt-add-repository ppa:dartsim/ppa
     (中略)   
     More info: https://launchpad.net/~dartsim/+archive/ubuntu/ppa
     Press [ENTER] to continue or Ctrl-c to cancel adding it.
    (中略) 
     取得:8 http://ppa.launchpad.net/dartsim/ppa/ubuntu focal InRelease [23.8 kB]
    (後略)
    

このリポジトリ追加がうまくいったと仮定する。次のコアライブラリのインストールはうまくいくだろうか。

$ sudo apt install libdart6-dev
(中略)
アップグレード: 0 個、新規インストール: 147 個、削除: 0 個、保留: 54 個。
47.3 MB のアーカイブを取得する必要があります。
この操作後に追加で 424 MB のディスク容量が消費されます。
続行しますか? [Y/n] Y
(中略)
パッケージからテンプレートを展開しています: 100%
以前に未選択のパッケージ libibverbs1:amd64 を選択しています。
(データベースを読み込んでいます ... 現在 159374 個のファイルとディレクトリがインストールされています。)
.../000-libibverbs1_28.0-1ubuntu1_amd64.deb を展開する準備をしています ...
(中略)

とてもではないがこんなにインストールできるのだろうか。

$ sudo apt install libdart6-collision-bullet-dev
(中略)
アップグレード: 0 個、新規インストール: 4 個、削除: 0 個、保留: 54 個。
2,057 kB のアーカイブを取得する必要があります。
この操作後に追加で 11.4 MB のディスク容量が消費されます。
続行しますか? [Y/n] Y
(中略)
$ 

うまくいったようだ。では、最後だ。

$ sudo apt install libdart6-all-dev
(中略)
アップグレード: 0 個、新規インストール: 111 個、削除: 0 個、保留: 54 個。
58.5 MB のアーカイブを取得する必要があります。
この操作後に追加で 268 MB のディスク容量が消費されます。
続行しますか? [Y/n] Y
(中略)
$

インストールはできたようだ。しかし、本当に動くのかだろうか。

$ dart
コマンド 'dart' が見つかりません。もしかして:

  command 'tart' from deb tart (3.10-1build1)
  command 'zart' from deb gmic-zart (2.4.5-1.1)
  command 'dat' from deb liballegro4-dev (2:4.4.3.1-1)
  command 'bart' from deb bart (0.5.00-1)
  command 'dact' from deb dact (0.8.42-5)
  command 'darts' from deb darts (0.32-20)
  command 'art' from deb artemis (17.0.1+dfsg-2)
  command 'dirt' from deb dput-ng (1.29)
  command 'dar' from deb dar (2.6.8-1)

次を試してみてください: sudo apt install <deb name>

あれれ。今までにインストールしたのは何だったのだろう。ひょっとして、 私が思った Dart ではないのかもしれない。実際、言語の Dart とは別の DART だった。そこで、別のところがないか探してみた。

すると、次のページが見つかった:
https://dart.dev/get-dart
ここには違うことが書かれていないか。ここの Linux の項をやってみる。

$ sudo apt update
(中略)
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
アップグレードできるパッケージが 54 個あります。表示するには 'apt list --upgradable' を実行してください。

ここには書かれていないがアップグレードをしてみる。

$ sudo apt update
(中略)

なんとか済んだようだ。

$ sudo apt install apt-transport-https

これは既にインストールされていた。次をためそう。

$ sudo sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
OK
$

あっけない。次いこう。

$ sudo sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
$

大丈夫だろう。

$ sudo apt update
(中略)
パッケージはすべて最新です。    

次が最後であってほしい。

$ sudo apt-get install dart
(中略)
$

よし。

$ ls /usr/lib/dart
LICENSE  README  bin  dartdoc_options.yaml  include  lib  version
$ 

パスを通す。これは、~/.profileに
export PATH="$PATH:/usr/lib/dart/bin
の行を付け加えただけだ。

$ dart
  ╔════════════════════════════════════════════════════════════════════════════╗
  ║ The Dart tool uses Google Analytics to anonymously report feature usage    ║
  ║ statistics, and crash reporting to send basic crash reports. This data is  ║
  ║ used to help improve the Dart platform and tools over time.                ║
  ║                                                                            ║
  ║ To disable reporting of anonymous tool usage statistics in general, run    ║
  ║ the command: `dart --disable-analytics`.                                   ║
  ╚════════════════════════════════════════════════════════════════════════════╝

A command-line utility for Dart development.

Usage: dart []  []

Global options:
-h, --help                 Print this usage information.
-v, --verbose              Show additional command output.
    --version              Print the Dart SDK version.
    --enable-analytics     Enable anonymous analytics.
    --disable-analytics    Disable anonymous analytics.

Available commands:
  analyze   Analyze the project's Dart code.
  compile   Compile Dart to various formats.
  create    Create a new project.
  format    Idiomatically format Dart source code.
  pub       Work with packages.
  run       Run a Dart program.
  test      Run tests in this package.

Run "dart help " for more information about a command.
See https://dart.dev/tools/dart-tool for detailed documentation.

よし。

$ cat saluton.dart
main() => print('Saluton, mondo!');
$ dart saluton.dart
Saluton, mondo!

これで起動も確かめられた。

こんどは Windows にインストール

上記のインストールはノートパソコンの WSL2 が対象だった。今度はデスクトップの Windows 11 Home Edition にインストールした。 まず管理者モードで Chocolatey をインストールした。そして、管理者モードで Dart をインストールした。

C: >dart --version
Dart SDK version: 2.19.6 (stable) (Tue Mar 28 13:41:04 2023 +0000) on "windows_x64"

書籍

まりんきょ学問所コンピュータの部屋コンピュータの本 > Dart


MARUYAMA Satosi