Ricerca nel sito web

Come installare il linguaggio di programmazione Swift su Ubuntu 20.04


Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Scarica Swift
  4. Installa Swift
  5. Connettiti a Swift Shell
  6. Conclusione

Swift è un linguaggio di programmazione generico, compilato e ad alte prestazioni con particolare attenzione alla sicurezza. È stato sviluppato da Apple in sostituzione del vecchio linguaggio Objective-C. È molto utile per chi vuole sviluppare applicazioni per macOS o iOS da Linux. È un linguaggio di programmazione intuitivo e amichevole per i nuovi programmatori. È ottimizzato per lo sviluppo e le prestazioni senza scendere a compromessi su nessuno dei due.

In questo post, ti mostreremo come installare il linguaggio di programmazione Swift su Ubuntu 20.04.

Prerequisiti

  • Un server che esegue Ubuntu 20.04.
  • Il server è configurato con una password di root.

Iniziare

Innanzitutto, dovrai aggiornare i tuoi pacchetti di sistema all'ultima versione. Puoi aggiornarli usando il seguente comando:

apt-get update -y
Swift all required some dependencies need to be install in your system. You can install all of them using the following command:
apt-get install binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 libz3-dev pkg-config tzdata zlib1g-dev -y

Una volta installate tutte le dipendenze, puoi procedere al passaggio successivo.

Scarica Swift

Innanzitutto, visita la pagina di download ufficiale di Swift e scarica l'ultima versione di Swift utilizzando il seguente comando:

wget https://swift.org/builds/swift-5.3.3-release/ubunt4/swift-5.3.3-RELEASE/swift-5.3.3-RELEASE-ubuntu20.04.tar.gz

Successivamente, scarica la firma PGP per verificare l'integrità del download utilizzando il seguente comando:

wget https://swift.org/builds/swift-5.3.3-release/ubunt4/swift-5.3.3-RELEASE/swift-5.3.3-RELEASE-ubuntu20.04.tar.gz.sig

Successivamente, importa la chiave PGP di Swift utilizzando il seguente comando:

gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys '7463 A81A 4B2E EA1B 551F FBCF D441 C977 412B 37AD' '1BE1 E29A 084C B305 F397 D62A 9F59 7F4D 21A5 6D5F' 'A3BA FD35 56A5 9079 C068 94BD 63BC 1CFE 91D3 06C6' '5E4D F843 FB06 5D7F 7E24 FBA2 EF54 30F0 71E1 B235' '8513 444E 2DA3 6B7C 1659 AF4D 7638 F1FB 2B2B 08C4' 'A62A E125 BBBF BB96 A6E0 42EC 925C C1CC ED3D 1561' '8A74 9566 2C3C D4AE 18D9 5637 FAF6 989E 1BC1 6FEA'

Successivamente, verifica l'integrità del file scaricato utilizzando il seguente comando:

gpg --verify swift-5.3.3-RELEASE-ubuntu20.04.tar.gz{.sig,}

Dovresti ottenere il seguente output:

gpg: Signature made Tue 26 Jan 2021 10:32:56 PM UTC
gpg:                using RSA key 925CC1CCED3D1561
gpg: Good signature from "Swift 5.x Release Signing Key <>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: A62A E125 BBBF BB96 A6E0  42EC 925C C1CC ED3D 1561

Installa Swift

Quindi, estrai il file scaricato utilizzando il seguente comando:

tar -xvzf swift-5.3.3-RELEASE-ubuntu20.04.tar.gz

Una volta estratto il file, sposta la directory estratta in /opt con il seguente comando:

mv swift-5.3.3-RELEASE-ubuntu20.04 /opt/swift

Successivamente, esporta il percorso di Swift nel file .bashrc:

echo "export PATH=/opt/swift/usr/bin:$PATH" >> ~/.bashrc

Successivamente, attiva il file .bashrc con il seguente comando:

source ~/.bashrc

Infine, verifica la versione di Swift utilizzando il seguente comando:

swift --version

Dovresti vedere il seguente output:

Swift version 5.3.3 (swift-5.3.3-RELEASE)
Target: x86_64-unknown-linux-gnu

Connettiti a Swift Shell

Ora puoi connetterti alla shell Swift chiamata REPL usando il seguente comando:

swift

Una volta connesso, dovresti vedere il seguente output:

Welcome to Swift version 5.3.3 (swift-5.3.3-RELEASE).
Type :help for assistance.

Ora, stampa il tuo nome usando il seguente comando:

  1> let name = "Hitesh Jethva"
name: String = "Hitesh Jethva"
  2> import Glibc // imports GNU C Library
  3> var ln = random() % 100
ln: Int = 83
  4> print("hello,",name,"your lucky number is", ln)
hello, Hitesh Jethva your lucky number is 83

Quindi, esci dalla shell Swift usando il seguente comando:

6> :q

Conclusione

Congratulazioni! hai installato con successo Swift su Ubuntu 20.04. Ora puoi iniziare a sviluppare la tua prima app per iOS utilizzando Swift.