Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lohenyumnam/16b2ebd2557974e5a0aaa9da29ffc056 to your computer and use it in GitHub Desktop.
Save lohenyumnam/16b2ebd2557974e5a0aaa9da29ffc056 to your computer and use it in GitHub Desktop.

Install Swift on Ubuntu 17.10, Sublime Text 3 Installation and setup for Swift

Step 1

Install ubuntu make

sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt update
sudo apt install ubuntu-make

Step 2

use ubuntu make to install swift Install the swift programing language

umake swift

Restart your Coputer

reboot

Step 3

Installing Sublime Text 3 on Ubuntu 17.10

Install the GPG key:

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -

Select the channel to use: Stable

echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

Update apt sources and install Sublime Text

sudo apt-get update
sudo apt-get install sublime-text

Then install Swift-Sublime-Package

  • Open the Command Pallette (ctrl + shift + p)
  • Type "install" and select "Package Control: Install Package"
  • Type "swift" and press Enter

Swift Compilation with Sublime Text 3 on Ubuntu 17.10

Adding Swift Build System

  • Open Sublime Text 3
  • Go To Preferences > Browse Packages...
  • Create a folder "SwiftBuilder" inside Packages directory.
  • Add a file named Swift.sublime-build inside SwiftBuilder directory.
  • Copy the following script in Swift.sublime-build file.
{
 	"shell_cmd": "swift \"$file\"",
 	"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
 	"working_dir": "${file_path}",
 	"selector": "source.swift",
}

Go to Preferences > Key Bindings-User and add the following script to it.

{
	"keys": ["super+b"],
	"command": "build",
	"context": [
	    { "key": "selector", "operator": "equal", "operand": "source.swift" }
	    ], 
	    
	    "args": {
	    "build_system": "Packages/SwiftBuilder/Swift.sublime-build",
	    "variant": "Build"
	    }
}

Done

@gaet2006
Copy link

Hey guys, I did this and when I try to run it in st3 it gives me this error:

bash: swift: command not found
[Finished in 0.0s with exit code 127]
[shell_cmd: swift "/home/gabriel/Documents/A.swift"]
[dir: /home/gabriel/Documents]
[path: /home/gabriel/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]

I checked in terminal (which I have set up w/ zsh) and typed in swift, and it worked perfectly. I then entered a bash shell and again typed in swift and, again, it worked perfectly.
I am not sure why it is giving me these errors. can someone please help me? Thanks!

@sheeong
Copy link

sheeong commented Dec 6, 2021

Same problem for me. The command swift is in the path but Sublime text incorrectly complained command was not found. Swift was not using the path reported by Swift. Sublime text may report the correct path but it is blindly using any path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment