安装ubuntu操作系统:
ubuntu22.04镜像注意:安装完千万不要更新,否则会出现toolbox build失败
开始搭建swift环境(官方文档:Vapor: Install → Linux)不过官方的文档需改造下:
1、安装swiftly:
$ curl -L https://swiftlang.github.io/swiftly/swiftly-install.sh | bash
2、安装swift (官方文档命令不可用)
$ swiftly install latest
Fetching the latest stable Swift release...
Installing Swift 5.9.1
Downloaded 488.5 MiB of 488.5 MiB
Extracting toolchain...
Swift 5.9.1 installed successfully!
$ swift --version
Swift version 5.9.1 (swift-5.9.1-RELEASE)
Target: x86_64-unknown-linux-gnu
此方法安装swift亲测可用
cd $HOME/.local/bin
chmod +x swiftly
./swiftly install latest
有时会出现这样的错误,多试几次: curl:(7)Failed to connect to github,com port 443 after 21024 ms: connection refused
安装完swift后添加环境:(nano ~/.bashrc)
对所有用户永久生效:
sudo nano /etc/profile
添加一行:export PATH=$PATH:~/.local/bin,其中~/.local/bin是你存放swift.sh文件的路径
更新一下 :source
~/.profileecho $PATH //查看环境变量是否配置成功
swift --version
3、安装Vapor Toolbox
git clone https://github.com/vapor/toolbox.git
经常出现clone不成功的情况,多试几次就好了
cd toolbox
git checkout <desired version> 可不执行
swift build -c release --disable-sandboxmv .build/release/vapor /usr/local/bin
最后查看是否安装成功:
vapor --help
4、创建项目
vapor new hello
cd /hello
swift build
swift run
(手动安装可参考大佬写的)Vapor-Ubuntu16.04环境搭建 - 简书
swift vapor 环境配置及运行https://zhuanlan.zhihu.com/p/138718198