2018年8月23日木曜日

OpenLayers5 Tutorials - 1a Building an OpenLayers Application

Introduction
はじめに

Modern JavaScript works best when using and authoring modules. The recommended way of using OpenLayers is installing the ol package. This tutorial walks you through setting up a simple dev environment, which requires node for everything to work.

モダンな JavaScript は、モジュールを使用して編集するとき最高の動作をします。OpenLayers を使用する推奨される方法は、ol パッケージをインストールすることです。このチュートリアルは、動作するすべての node を必要とする簡単な開発環境を設定をします。

In this tutorial, we will be using Parcel to bundle our application. There are several other options, some of which are linked from the README.

このチュートリアルは、アプリケーションをパンドルするための Parcel を使用します。他にもいくつかのオプションがあり、README からリンクされたものもあります。


■□ Debian9 で試します■□
Debian9(stretch)に、最新の Node.js をインストールしてみます。Debian9.5 にアップデートしたとき、更新されなかった APT も修正しています。

「How to Install Latest NodeJs & NPM on Debian 9/8/7(https://tecadmin.net/install-latest-nodejs-npm-on-debian/)」と「パッケージマネージャを利用した Node.js のインストール(https://nodejs.org/ja/download/package-manager/)」、「NodeSource Node.js Binary Distributions(https://github.com/nodesource/distributions)」を参考にします。

最初に、「curl」をインストールします。「curl(https://curl.haxx.se/)」は、コマンドライン、または、スクリプトでデータを転送するために使用されます。

root@deb9-vmw:~# apt-cache policy curl
curl:
  インストールされているバージョン: (なし)
  候補:               7.52.1-5+deb9u6
  バージョンテーブル:
     7.52.1-5+deb9u6 500
        500 http://ftp.jp.debian.org/debian stretch/main amd64 Packages
user@deb9-vmw:~$ su -
パスワード:
root@deb9-vmw:~# apt-get install curl
root@deb9-vmw:~# apt-cache policy curl
curl:
  インストールされているバージョン: 7.52.1-5+deb9u6
  候補:               7.52.1-5+deb9u6
  バージョンテーブル:
 *** 7.52.1-5+deb9u6 500
        500 http://ftp.jp.debian.org/debian stretch/main amd64 Packages
        100 /var/lib/dpkg/status
次に、node.js をインストールします。一緒に NPM もインストールされます。「npm(https://www.npmjs.com/)」は、JavaScript と世界最大のソフトウェアレジストリのパッケージマネージャです。
root@deb9-vmw:~# curl -sL https://deb.nodesource.com/setup_8.x | bash -

## Installing the NodeSource Node.js 8.x LTS Carbon repo...


## Populating apt-get cache...

+ apt-get update
無視:1 http://ftp.jp.debian.org/debian stretch InRelease
---
無視:15 http://deb.debian.org/debian stretch/updates/main DEP-11 64x64 Icons
パッケージリストを読み込んでいます... 完了
W: http://ftp.jp.debian.org/debian/dists/stretch-updates/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg are ignored as the file is not readable by user '_apt' executing apt-key.
W: http://ftp.jp.debian.org/debian/dists/stretch/Release.gpg: The key(s) in the keyring /etc/apt/trusted.gpg are ignored as the file is not readable by user '_apt' executing apt-key.
W: リポジトリ http://deb.debian.org/debian stretch/updates Release には Release ファイルがありません。
N: このようなリポジトリから取得したデータは認証できないので、データの使用は潜在的に危険です。
N: リポジトリの作成とユーザ設定の詳細は、apt-secure(8) man ページを参照してください。
E: http://deb.debian.org/debian/dists/stretch/updates/main/source/Sources の取得に失敗しました  404  Not Found [IP: 151.101.196.204 80]
E: いくつかのインデックスファイルのダウンロードに失敗しました。これらは無視されるか、古いものが代わりに使われます。
Error executing command, exiting

次に、node.js をインストールします。一緒に NPM もインストールされます。「npm(https://www.npmjs.com/)」は、JavaScript と世界最大のソフトウェアレジストリのパッケージマネージャです。

root@deb9-vmw:~# apt-get install -y nodejs
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  libuv1
以下のパッケージが新たにインストールされます:
  libuv1 nodejs
アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
3,524 kB 中 0 B のアーカイブを取得する必要があります。
この操作後に追加で 14.5 MB のディスク容量が消費されます。
以前に未選択のパッケージ libuv1:amd64 を選択しています。
(データベースを読み込んでいます ... 現在 174735 個のファイルとディレクトリがインストールされています。)
.../libuv1_1.9.1-3_amd64.deb を展開する準備をしています ...
libuv1:amd64 (1.9.1-3) を展開しています...
以前に未選択のパッケージ nodejs を選択しています。
.../nodejs_4.8.2~dfsg-1_amd64.deb を展開する準備をしています ...
nodejs (4.8.2~dfsg-1) を展開しています...
libuv1:amd64 (1.9.1-3) を設定しています ...
libc-bin (2.24-11+deb9u3) のトリガを処理しています ...
man-db (2.7.6.1-2) のトリガを処理しています ...
nodejs (4.8.2~dfsg-1) を設定しています ...
update-alternatives: /usr/bin/js (js) を提供するために自動モードで /usr/bin/nodejs を使います

それでは、node.js と npm のバージョンを確認します。

root@deb9-vmw:~# exit
ログアウト
user@deb9-vmw:~$ node -v
-su: node: コマンドが見つかりません
user@deb9-vmw:~$ npm -v
-su: npm: コマンドが見つかりません

インストールに失敗しているようです。nodejs のバージョンを見てみると古いバージョンがインストールされています。

root@deb9-vmw:~# nodejs -v
v4.8.2

色々メッセージが表示されていますが、「The key(s) in the keyring /etc/apt/trusted.gpg are ignored as the file is not readable by user '_apt' executing apt-key.」で検索した結果、aptが実行前にサーバが正しいかどうかを公開鍵でするチェックに問題があるようです。『Debian テスト版の「apt-get update時の警告メッセージ」(https://blogs.yahoo.co.jp/jeaou/40499468.html)』を参考に次のようにしました。
以前から Synaptic パッケージマネージャで「パッケージ情報の再読込」を実行すると同様のメッセージが表示されていました。

nodejs を削除します。

root@deb9-vmw:~# apt remove nodejs
root@deb9-vmw:~# apt autoremove

公開鍵を /etc/apt/trusted.gpg に変更します。

root@deb9-vmw:~# mv /etc/apt/trusted.gpg /etc/apt/trusted.gpg_org
root@deb9-vmw:~# cp /usr/share/keyrings/debian-archive-keyring.gpg /etc/apt/trusted.gpg

「W: リポジトリ http://deb.debian.org/debian stretch/updates Release には Release ファイルがありません。」で検索した結果、 /etc/apt/sources.list の「deb http://deb.debian.org/debian/ stretch/updates」に問題があるようです。「Debian: The repository does not have a Release file(https://unix.stackexchange.com/questions/371890/debian-the-repository-does-not-have-a-release-file)」を参考に /etc/apt/sources.list の次の行を修正します。

root@deb9-vmw:~# vim /etc/apt/sources.list
---
# deb http://deb.debian.org/debian/ stretch/updates main
# deb-src http://deb.debian.org/debian/ stretch/updates main

deb http://security.debian.org/debian-security stretch/updates main
deb-src http://security.debian.org/debian-security stretch/updates main
---

再度、node.js をインストールします。
root@deb9-vmw:~# curl -sL https://deb.nodesource.com/setup_8.x | bash -

## Installing the NodeSource Node.js 8.x LTS Carbon repo...


## Populating apt-get cache...

+ apt-get update
無視:1 http://ftp.jp.debian.org/debian stretch InRelease
ヒット:2 http://ftp.jp.debian.org/debian stretch-updates InRelease        
ヒット:3 http://ftp.jp.debian.org/debian stretch Release                       
ヒット:4 http://security.debian.org/debian-security stretch/updates InRelease  
パッケージリストを読み込んでいます... 完了                 

## Installing packages required for setup: apt-transport-https...

+ apt-get install -y apt-transport-https > /dev/null 2>&1

## Confirming "stretch" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_8.x/dists/stretch/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
OK

## Creating apt sources list file for the NodeSource Node.js 8.x LTS Carbon repo...

+ echo 'deb https://deb.nodesource.com/node_8.x stretch main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src https://deb.nodesource.com/node_8.x stretch main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
無視:1 http://ftp.jp.debian.org/debian stretch InRelease
ヒット:2 http://ftp.jp.debian.org/debian stretch-updates InRelease             
ヒット:3 http://ftp.jp.debian.org/debian stretch Release                       
ヒット:4 http://security.debian.org/debian-security stretch/updates InRelease  
取得:6 https://deb.nodesource.com/node_8.x stretch InRelease [4,647 B]
取得:7 https://deb.nodesource.com/node_8.x stretch/main Sources [762 B]
取得:8 https://deb.nodesource.com/node_8.x stretch/main amd64 Packages [1,006 B]
6,415 B を 1秒 で取得しました (5,263 B/s)
パッケージリストを読み込んでいます... 完了

## Run `sudo apt-get install -y nodejs` to install Node.js 8.x LTS Carbon and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
     echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn
root@deb9-vmw:~# apt-get install -y nodejs
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
  nodejs
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
12.7 MB のアーカイブを取得する必要があります。
この操作後に追加で 61.4 MB のディスク容量が消費されます。
取得:1 https://deb.nodesource.com/node_8.x stretch/main amd64 nodejs amd64 8.11.3-1nodesource1 [12.7 MB]
12.7 MB を 9秒 で取得しました (1,380 kB/s)
以前に未選択のパッケージ nodejs を選択しています。
(データベースを読み込んでいます ... 現在 174743 個のファイルとディレクトリがインストールされています。)
.../nodejs_8.11.3-1nodesource1_amd64.deb を展開する準備をしています ...
nodejs (8.11.3-1nodesource1) を展開しています...
nodejs (8.11.3-1nodesource1) を設定しています ...
man-db (2.7.6.1-2) のトリガを処理しています ...
それでは、node.js と npm のバージョンを確認します。

root@deb9-vmw:~# exit
ログアウト
user@deb9-vmw:~$ node -v
v8.11.3
user@deb9-vmw:~$ npm -v
5.6.0

java のバージョンを確認します。(Debian 9 - 10 Eclipse 4.7 "Oxygen" の設定(2017年7月13日木曜日のブログ)で Java を設定しました。)

user@deb9-vmw:~$ java -version
java version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-1~deb9u1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

node.js のインストールをテストするために、webサーバを作成します。次の内容で http_sever.js を作成します。

user@deb9-vmw:~$ vim http_server.js
var http = require('http');
http.createServer(function (req, res) {
 res.writeHead(200, {'Content-Type': 'text/plain'});
 res.end('Hello World\n');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');

次のコマンドで web サーバを起動します。

user@deb9-vmw:~$ node http_server.js
Server running at http://127.0.0.1:3000/

Webブラウザのアドレス欄に

http://127.0.0.1:3000/

と入力して Enter キーを押します。


■□ここまで■□

続く...

0 件のコメント: