iOSアプリ開発のための言語と思っていたSwiftで何とWebアプリケーションが開発出来るそうで、ひとまず環境を構築してみました。
以前構築したこの環境を使いました。
OS: Ubuntu16.04
Swift: 4.2.3
Vapor: 3.3.0
vagrant環境に接続して、ひたすらコマンドです。
sudo su -
cd /tmp
apt-get update
apt-get install -y clang libpython2.7 libxml2
wget https://swift.org/builds/swift-4.2.3-release/ubuntu1604/swift-4.2.3-RELEASE/swift-4.2.3-RELEASE-ubuntu16.04.tar.gz
tar zxfv swift-4.2.3-RELEASE-ubuntu16.04.tar.gz
mkdir /usr/local/swift
mv swift-4.2.3-RELEASE-ubuntu16.04 /usr/local/swift/
ln -s /usr/local/swift/swift-4.2.3-RELEASE-ubuntu16.04/usr/bin/swift /usr/local/bin/swift
swift --version
Swift version 4.2.3 (swift-4.2.3-RELEASE)
Target: x86_64-unknown-linux-gnu
wget -q https://repo.vapor.codes/apt/keyring.gpg -O- | sudo apt-key add -
echo "deb https://repo.vapor.codes/apt $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/vapor.list
apt-get update
apt-get install -y swift vapor
vapor --help
で下記が表示されればインストール済み。
Usage: vapor command
Join our team chat if you have questions, need help,
or want to contribute: http://vapor.team
Commands:
new Creates a new Vapor application from a template.
Use --template=repo/template for github templates
Use --template=full-url-here.git for non github templates
Use --web to create a new web app
Use --auth to create a new authenticated API app
Use --api (default) to create a new API
build Compiles the application.
run Runs the compiled application.
fetch Fetches the application's dependencies.
update Updates your dependencies.
clean Cleans temporary files--usually fixes
a plethora of bizarre build errors.
test Runs the application's tests.
xcode Generates an Xcode project for development.
Additionally links commonly used libraries.
version Displays Vapor CLI version
cloud Commands for interacting with Vapor Cloud.
heroku Commands to help deploy to Heroku.
provider Commands to help manage providers.
Use `vapor command --help` for more information on a command.
あとはrootユーザは抜けて、プロジェクト作成です。
mkdir webapps
cd webapps/
vapor new web_blank
続いて
cd web_blank
vapor build
vapor run serve
まで実行して、localhost:8080
にアクセスします。
OK!