Sunday, January 16, 2022

Server-Side Swift Developer Blog Entry #0x00: Vapor on Windows with Windows Subsystem for Linux

 Server-Side Swift (Vapor) on Windows 11 inside WSL with Visual Studio Code

Install Ubuntu via the Microsoft store or WSL command line. This may require rebooting.

Open an ubuntu/bash terminal.

Check for any updates:

    sudo apt-get update

    sudo apt-get upgrade -y

Install prerequesites

    sudo apt-get install -y binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 libz3-dev pkg-config tzdata uuid-dev zlib1g-dev make

Grab the latest swift 5.5 as of this writing

    wget https://download.swift.org/swift-5.5-branch/ubuntu2004/swift-5.5-DEVELOPMENT-SNAPSHOT-2021-12-07-a/swift-5.5-DEVELOPMENT-SNAPSHOT-2021-12-07-a-ubuntu20.04.tar.gz

untar it

    tar xzf swift-5.5-DEVELOPMENT-SNAPSHOT-2021-12-07-a-ubuntu20.04.tar.gz 

set the swift path

    export PATH=/home/YOURLINUXUSERNAME/swift-5.5-DEVELOPMENT-SNAPSHOT-2021-12-07-a-ubuntu20.04/usr/bin:"{$PATH}"

test that swift works

    swift --version

install vapor toolbox

    git clone https://github.com/vapor/toolbox.git

    cd toolbox

    git checkout 18.3.3

    make install

check that vapor worked

    vapor --help

make a project directory and try out a vapor demo app
    mkdir vapordevprojects
    cd vapordevprojects
    vapor new HelloVaporDeveloper
        <I selected Fluent, with SQLite, and did not opt to use leaf>
    cd HelloVaporDeveloper
    vapor run

you may encounter an issue with sqlite, to fix it try
    sudo apt-get install libsqlite3-dev

install visual studio code for windows (if you install it in ubuntu and then try launching it, it tells you to uninstall it and then use the windows version

at the terminal you should be able to type
    code .

and open the source code on windows

No comments:

Post a Comment