{"id":4328,"date":"2026-03-27T08:36:41","date_gmt":"2026-03-27T05:36:41","guid":{"rendered":"https:\/\/demensdeum.com\/blog\/2026\/03\/27\/swift-wsl2-linux-build\/"},"modified":"2026-03-27T08:47:29","modified_gmt":"2026-03-27T05:47:29","slug":"swift-wsl2-linux-build","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/2026\/03\/27\/swift-wsl2-linux-build\/","title":{"rendered":"Building Swift in WSL2 (Linux)"},"content":{"rendered":"<p>The Swift ecosystem is actively developing outside of Apple platforms, and today it is quite comfortable to write in it under Windows using the Windows Subsystem for Linux (WSL2). It is worth considering that for assemblies under Linux\/WSL, a lightweight version of Swift is available &#8211; without proprietary Apple frameworks (such as SwiftUI, UIKit, AppKit, CoreData, CoreML, ARKit, SpriteKit and other iOS\/macOS-specific libraries), but for console utilities and the backend this is more than enough. In this post, we will walk through the process of preparing the environment and building the Swift compiler from source code inside WSL2 step by step (using Ubuntu\/Debian as an example).<\/p>\n<p>We update the list of packages and the system itself:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>sudo apt update && sudo apt upgrade -y\n<\/code><\/pre>\n<\/div>\n<p>Install the necessary dependencies for the build:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>sudo apt install -y \\\n  git cmake ninja-build clang python3 python3-pip \\\n  libicu-dev libxml2-dev libcurl4-openssl-dev \\\n  libedit-dev libsqlite3-dev swig libncurses5-dev \\\n  pkg-config tzdata rsync\n<\/code><\/pre>\n<\/div>\n<p>Install the compiler and linker (LLVM and LLD):<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>sudo apt install -y llvm lld\n<\/code><\/pre>\n<\/div>\n<p>Clone the Swift repository with all dependencies:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>git clone https:\/\/github.com\/apple\/swift.git\ncd swift\nutils\/update-checkout --clone\n<\/code><\/pre>\n<\/div>\n<p>Install `swiftly` and ready-made swift with swiftc<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>curl -O https:\/\/download.swift.org\/swiftly\/linux\/swiftly-$(uname -m).tar.gz && \\\ntar zxf swiftly-$(uname -m).tar.gz && \\\n.\/swiftly init --quiet-shell-followup && \\\n. \"${SWIFTLY_HOME_DIR:-$HOME\/.local\/share\/swiftly}\/env.sh\" && \\\nhash -r\n<\/code><\/pre>\n<\/div>\n<p>Let&#8217;s start the build (this will take a long time):<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>utils\/build-script \\\n  --release-debuginfo \\\n  --swift-darwin-supported-archs=\"x86_64\" \\\n  --llvm-targets-to-build=\"X86\" \\\n  --skip-build-benchmarks \\\n  --skip-test-cmark \\\n  --skip-test-swift \\\n  --skip-ios \\\n  --skip-tvos \\\n  --skip-watchos \\\n  --skip-build-libdispatch=false \\\n  --skip-build-cmark=false \\\n  --skip-build-foundation \\\n  --skip-build-lldb \\\n  --skip-build-xctest \\\n  --skip-test-swift\n<\/code><\/pre>\n<\/div>\n<p>After the build is complete, add the path to the compiler to PATH (specify your path to the build folder):<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>export PATH=\/root\/Sources\/3rdparty\/build\/Ninja-RelWithDebInfoAssert\/swift-linux-x86_64\/bin\/swiftc:$PATH\n<\/code><\/pre>\n<\/div>\n<p>We check that the installed version of Swift is working:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>swift --version\n<\/code><\/pre>\n<\/div>\n<p>Create a test file and run it:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>echo \"print(\\\"Hello, World!\\\")\" > hello.swift\nswift hello.swift\n<\/code><\/pre>\n<\/div>\n<p>You can also compile the binary and run it:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>swiftc hello.swift\n.\/hello\n<\/code><\/pre>\n<\/div>\n<h3>Sources<\/h3>\n<ul>\n<li><a href=\"https:\/\/www.swift.org\/getting-started\/windows\/\">Getting Started with Swift on Windows<\/a><\/li>\n<li><a href=\"https:\/\/swiftlang.github.io\/swiftly\/\">Swiftly (version control tool)<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/apple\/swift\/blob\/main\/docs\/HowToGuides\/GettingStarted.md\">Building Swift from source code<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The Swift ecosystem is actively developing outside of Apple platforms, and today it is quite comfortable to write in it under Windows using the Windows Subsystem for Linux (WSL2). It is worth considering that for assemblies under Linux\/WSL, a lightweight version of Swift is available &#8211; without proprietary Apple frameworks (such as SwiftUI, UIKit, AppKit,<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/2026\/03\/27\/swift-wsl2-linux-build\/\">Continue reading <span class=\"screen-reader-text\">&#8220;Building Swift in WSL2 (Linux)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[61,52],"tags":[],"class_list":["post-4328","post","type-post","status-publish","format-standard","hentry","category-techie","category-tutorials","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"en","enabled_languages":["en","ru","zh","de","fr","ja","pt"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"ru":{"title":true,"content":true,"excerpt":false},"zh":{"title":true,"content":true,"excerpt":false},"de":{"title":true,"content":true,"excerpt":false},"fr":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/posts\/4328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/comments?post=4328"}],"version-history":[{"count":4,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/posts\/4328\/revisions"}],"predecessor-version":[{"id":4333,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/posts\/4328\/revisions\/4333"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/media?parent=4328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/categories?post=4328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/tags?post=4328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}