# Additional Linux Distributions

**URL:** <https://forums.swift.org/t/additional-linux-distributions/36188>\
**Category:** Development\
**Created:** [May 5, 2020, 8:19pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188 "2020-05-05T20:19:43Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [May 8, 2020, 3:18am UTC](https://forums.swift.org/t/additional-linux-distributions/36188/21 "2020-05-08T03:18:58Z")

</div>

> [@svanimpe](#):
>
> This used to be only clang and libicu-dev (and git for SwiftPM). Are these really all required for running Swift (not building it from source)? Or did you replace clang by its dependencies?

@svanimpe installing `clang` and `libicu-dev` will result in installing all the same packages, and the new list is actually more accurate. I understand your concern that the new `apt-get install` command is longer in form, but it will actually install less packages. As mentioned above I share you desire to pair down this list further and see Swift distributed as a formal package in the upstream repositories

---

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [May 8, 2020, 3:22am UTC](https://forums.swift.org/t/additional-linux-distributions/36188/22 "2020-05-08T03:22:48Z")

</div>

> [@SusanCheng](#):
>
> Yes, but the header file is missing. The Ubuntu version comes with the zlib1g-dev installed.

@SusanCheng does your program need `zlib-devel`, or do you see Swift toolchain requiring it? I am aware many applications need it, but IIRC Swift itself does not.

PS, it may be a good idea to include `zlib-devel`, I am just wondering where you see the error.

---

<div class="post-metadata">

**Author:** ![SusanCheng](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/susancheng/32/9439_2.png) [@SusanCheng](https://forums.swift.org/u/SusanCheng)\
**Post date:** [May 8, 2020, 3:27am UTC](https://forums.swift.org/t/additional-linux-distributions/36188/23 "2020-05-08T03:27:33Z")

</div>

Yes, my library requires zlib-devel. I got the missing header file error when I try to build with centos docker image.

> **[GitHub - SusanDoggie/Doggie: A Cross-platform Library for Swift](https://github.com/SusanDoggie/Doggie)**
>
> A Cross-platform Library for Swift. Contribute to SusanDoggie/Doggie development by creating an account on GitHub.

I just added the zlib-devel to the build script to pass ci.

---

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [May 8, 2020, 3:32am UTC](https://forums.swift.org/t/additional-linux-distributions/36188/24 "2020-05-08T03:32:08Z")

</div>

> [@SusanCheng](#):
>
> Yes, my library requires zlib-devel.

makes sense, the issue with including dependencies that are not strictly required by Swift itself is that its a slippery slope, this is especially true when building Docker images since we want to maintain them as small as possible

---

<div class="post-metadata">

**Author:** ![mishal\_shah](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mishal_shah/32/247_2.png) [@mishal\_shah](https://forums.swift.org/u/mishal_shah)\
**Post date:** [May 8, 2020, 6:01am UTC](https://forums.swift.org/t/additional-linux-distributions/36188/25 "2020-05-08T06:01:37Z")

</div>

> [@svanimpe](#):
>
> Isn’t it a dependency of the Swift Package Manager?

The latest nightly docker images now has `git` installed.

---

<div class="post-metadata">

**Author:** ![Ron\_Olson](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ron_olson/32/1325_2.png) [@Ron\_Olson](https://forums.swift.org/u/Ron_Olson)\
**Post date:** [May 8, 2020, 12:14pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/26 "2020-05-08T12:14:15Z")

</div>

Swift is in the official Fedora/RH 8/CentOS repos. I've been working on making a formal Ubuntu package as well; I was sidetracked because of packaging issues with Fedora, but now that is taken care of I am picking up where I left off on Ubuntu.

---

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [May 8, 2020, 7:32pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/27 "2020-05-08T19:32:12Z")

</div>

> [@Ron\_Olson](#):
>
> Swift is in the official Fedora/RH 8/CentOS repos. I've been working on making a formal Ubuntu package as well; I was sidetracked because of packaging issues with Fedora, but now that is taken care of I am picking up where I left off on Ubuntu.

This is fantastic news. Are you able you utilize the tarball from [swift.org](http://swift.org) or do you build Swift yourself for Fedora/RH 8/CentOS

---

<div class="post-metadata">

**Author:** ![Ron\_Olson](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ron_olson/32/1325_2.png) [@Ron\_Olson](https://forums.swift.org/u/Ron_Olson)\
**Post date:** [May 8, 2020, 7:36pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/28 "2020-05-08T19:36:45Z")

</div>

Fedora has a requirement that everything be built from source, so it takes awhile to build the package. 🙂

If you're interested, all the files I use to package Swift for Fedora/RH/CentOS are available [here](https://src.fedoraproject.org/rpms/swift-lang). The "Makefile" that drives creating the package is the [spec file](https://src.fedoraproject.org/rpms/swift-lang/blob/master/f/swift-lang.spec).

---

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [May 8, 2020, 8:01pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/29 "2020-05-08T20:01:17Z")

</div>

thanks for sharing this @Ron_Olson, very helpful. there are fews areas I think we could work towards:

1. make sure we use the minimal set of dependencies to do the Swift build from source. you can find what we came up with in the new Docker area, e.g. [https://github.com/apple/swift-docker/blob/master/swift-ci/master/centos/8/Dockerfile](https://github.com/apple/swift-docker/blob/master/swift-ci/master/centos/8/Dockerfile)
2. minimize the amount of patches you need to do on top of the source so it builds out-of-the box. @drexin done a bunch of changes to that end for the new distros, would be interesting to see what you still need to patch on-top to make Fedora/RH build and work together to eliminate that.
3. have tests run and pass.

---

<div class="post-metadata">

**Author:** ![Ron\_Olson](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ron_olson/32/1325_2.png) [@Ron\_Olson](https://forums.swift.org/u/Ron_Olson)\
**Post date:** [May 8, 2020, 10:21pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/30 "2020-05-08T22:21:45Z")

</div>

Yep, I'm basing my Dockerfile on the CentOS one. The patches I use are a consequence of Fedora moving very aggressively to the latest-n-greatest kernels, packages, etc. which acts as a good bellwether of what is going to eventually come to _all_ Linux distros and where possible I submit PRs (e.g. [this one](https://github.com/apple/swift-corelibs-foundation/pull/2771)) but those typically come too late for the coming Swift release; while they're merged in master, I have to keep my patch around to the next release where I can remove it. Also in the case of building for Linux on the s390x architecture, I needed a patch that I didn't submit a PR for as I saw in master the code had been refactored completely.

Another area where Fedora is very aggressive is in the move to Python 3; I know @drexin, et al. have been moving aggressively in this area and it really shows in the nightly builds I do from master as well as the latest 5.3 snapshot, so I'm definitely looking forward to retiring all my Python 3 patches. 🙂

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [May 8, 2020, 10:28pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/31 "2020-05-08T22:28:53Z")

</div>

In case you are interested: `https://swift.apt.compnerd.org/apt` is an apt repository which contains a dpkg from the hourly builds from master.

The build rules are at [GitHub - compnerd/swift-build: Alternate Swift Builds](https://github.com/compnerd/swift-build) and the builds occur at [https://dev.azure.com/compnerd/swift-build/\_build?definitionId=14](https://dev.azure.com/compnerd/swift-build/_build?definitionId=14).

---

<div class="post-metadata">

**Author:** ![Ron\_Olson](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ron_olson/32/1325_2.png) [@Ron\_Olson](https://forums.swift.org/u/Ron_Olson)\
**Post date:** [May 8, 2020, 10:40pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/32 "2020-05-08T22:40:56Z")

</div>

Awesome! Thanks Saleem for the info!

---

<div class="post-metadata">

**Author:** ![schafdog](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@schafdog](https://forums.swift.org/u/schafdog)\
**Post date:** [May 9, 2020, 11:01am UTC](https://forums.swift.org/t/additional-linux-distributions/36188/33 "2020-05-09T11:01:14Z")

</div>

Is there a place I can see the script that builds the tool chains? I guess it must be somewhere on the ci server, but I haven't figure out how to see that.

---

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [May 9, 2020, 8:47pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/34 "2020-05-09T20:47:37Z")

</div>

> [@schafdog](#):
>
> Is there a place I can see the script that builds the tool chains? I guess it must be somewhere on the ci server, but I haven't figure out how to see that.

just opened a PR with this info. still needs to be reviewed, but potentially helpful: [add guide for adding ci dockerfiles to support more distributions by tomerd · Pull Request #171 · apple/swift-docker · GitHub](https://github.com/apple/swift-docker/pull/171)

---

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [May 9, 2020, 9:24pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/35 "2020-05-09T21:24:08Z")

</div>

> [@Max\_Desiatov](#):
>
> This is amazing! Are there any plans to support Alpine? I had some attempts to make it build on Alpine, but that seemed like a project big enough on its own. Is supporting Alpine even on the roadmap? This would greatly help in reducing sizes of Docker images for certain tasks.

> [@IOOI](#):
>
> In a similar discussion [here](https://forums.swift.org/t/vapor-4-deployment-on-small-docker-image-like-for-instance-12-1-alpine/34727) there was a post that somebody succeeded using SCRATCH instead of Alpine: [Vapor 4 deployment on small docker image like for instance 12.1-alpine](https://forums.swift.org/t/vapor-4-deployment-on-small-docker-image-like-for-instance-12-1-alpine/34727/13) . I don't know if that would be sufficient for you.
> 
> Another discussion on that topic from a year ago can be found here: [Idea: runtime/slim images](https://forums.swift.org/t/idea-runtime-slim-images/22695)

In addition to the `slim` images mentioned above which we publish for ubuntu (CentOS and Amazon Linux 2 dont need anything on top of the distro for _running_ swift programs), another option that folks could find interesting is Google's [distroless](https://github.com/GoogleContainerTools/distroless). I did a small experiment today:

```dockerfile
FROM swiftlang/swift:nightly-bionic as build

# build a test application, real world examples would add the actual source instead
RUN mkdir /workspace
WORKDIR /workspace
RUN swift package init --name test --type executable
RUN echo "import Foundation\n \
\n \
let dateFormatter = DateFormatter()\n \
dateFormatter.dateFormat = \"yyyy-MM-dd HH:mm:ss Z\"\n \
dateFormatter.timeZone = TimeZone(abbreviation: \"PST\")\n \
\n \
print(\"Hello, world!\")\n \
print(\"The time is \(dateFormatter.string(from: Date()))\")\n \
" > Sources/test/main.swift
RUN swift build -c release

# copy executables and dependencies on top of the base image
FROM gcr.io/distroless/cc-debian10
COPY --from=build /workspace/.build/release /
COPY --from=build /usr/lib/swift/linux/lib*so* /

# set the entry point (application name)
CMD ["/test"]

```

and the results:

```bash
❯ docker build . -t swift-distroless-test
Sending build context to Docker daemon 2.56kB
...
Successfully built 101536fea410
Successfully tagged swift-distroless-test:latest

❯ docker run swift-distroless-test
Hello, world!
The time is 2020-05-09 14:21:36 -0700

```

Note the above this uses `gcr.io/distroless/cc-debian10` as the runtime image which should work for Swift programs that do not use `FoundationNetworking` or `FoundationXML`. In order to provide a more complete support we (the community) could put in a PR into [distroless](https://github.com/GoogleContainerTools/distroless) to introduce a base image for Swift that includes `libcurl` and `libxml` which are required for `FoundationNetworking` or `FoundationXML respectively.

---

<div class="post-metadata">

**Author:** ![thulir1](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/thulir1/32/11995_2.png) [@thulir1](https://forums.swift.org/u/thulir1)\
**Post date:** [May 10, 2020, 5:39am UTC](https://forums.swift.org/t/additional-linux-distributions/36188/36 "2020-05-10T05:39:30Z")

</div>

Thank you for the information, can any of you please reply to my query.

---

<div class="post-metadata">

**Author:** ![Optional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/optional/32/12543_2.png) [@Optional](https://forums.swift.org/u/Optional)\
**Post date:** [May 11, 2020, 2:15am UTC](https://forums.swift.org/t/additional-linux-distributions/36188/37 "2020-05-11T02:15:46Z")

</div>

Can we use the script to install swift on linux? like: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`

---

<div class="post-metadata">

**Author:** ![gonsolo](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@gonsolo](https://forums.swift.org/u/gonsolo)\
**Post date:** [May 13, 2020, 11:30am UTC](https://forums.swift.org/t/additional-linux-distributions/36188/38 "2020-05-13T11:30:16Z")

</div>

> [@compnerd](#):
>
> In case you are interested: `https://swift.apt.compnerd.org/apt` is an apt repository which contains a dpkg from the hourly builds from master

```
sudo echo "deb [trusted=yes] https://swift.apt.compnerd.org/apt /" > /etc/apt/sources.list.d/swift.list
sudo apt update
sudo apt install swift-toolchain

```

worked for me but swift fails with:

`<unknown>:0: error: unable to load standard library for target 'x86_64-unknown-linux-gnu'`

Also I guess "swift package init" is not yet supported?

---

<div class="post-metadata">

**Author:** ![IOOI](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/iooi/32/870_2.png) [@IOOI](https://forums.swift.org/u/IOOI)\
**Post date:** [May 13, 2020, 2:59pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/39 "2020-05-13T14:59:00Z")

</div>

> [@Optional](#):
>
> Can we use the script to install swift on linux? like: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`

You might be interested in this: [Introducing swiftbox 0.10 with CentOS(RHEL) and Amazon Linux support](https://forums.swift.org/t/introducing-swiftbox-0-10-with-centos-rhel-and-amazon-linux-support/36431)

regards,

Lars

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [May 13, 2020, 4:24pm UTC](https://forums.swift.org/t/additional-linux-distributions/36188/40 "2020-05-13T16:24:39Z")

</div>

Oh, the layout is similar to that on Windows, so you will need the `-sdk` flags.

I think that s-p-m builds are integrated into the packaging, help to add that is welcome :)

[Previous page](https://forums.swift.org/t/additional-linux-distributions/36188.md?page=1)

[Next page](https://forums.swift.org/t/additional-linux-distributions/36188.md?page=3)
