{"id":56,"date":"2020-02-20T19:59:55","date_gmt":"2020-02-20T19:59:55","guid":{"rendered":"https:\/\/www.aya.io\/ayablog\/?p=56"},"modified":"2022-02-07T02:36:09","modified_gmt":"2022-02-07T02:36:09","slug":"swift-5-in-vscode-in-linux-mint-in-virtualbox","status":"publish","type":"post","link":"https:\/\/www.aya.io\/blog\/swift-5-in-vscode-in-linux-mint-in-virtualbox\/","title":{"rendered":"Swift 5 in VSCode in Linux Mint in VirtualBox"},"content":{"rendered":"<p>Getting VSCode on Linux Mint to properly run Swift with sourcekit-lsp in order to get syntax highlighting and code completion can be rather convoluted. <\/p>\n<p>Here's how I did it.<\/p>\n<p><!-- more --><\/p>\n<h1>First steps<\/h1>\n<ul>\n<li>Download and install VirtualBox 6.0.<\/li>\n<li>Download Linux Mint Xfce 19.3.<\/li>\n<\/ul>\n<p>In VirtualBox, create a new virtual machine with these settings:<\/p>\n<ul>\n<li>Dynamic VDI disk, at least 40GB<\/li>\n<li>Chipset PIIX3<\/li>\n<li>At least 4GB RAM<\/li>\n<li>Activate IO-APIC (do not check EFI)<\/li>\n<li>UTC clock<\/li>\n<li>Activate PAE\/NX (do not check VT-x)<\/li>\n<li>1 CPU runs ok, but 2 or more is better<\/li>\n<li>100% resources<\/li>\n<li>Activate pagination<\/li>\n<li>Graphics driver must be VMSVGA<\/li>\n<li>64 MO video RAM or more<\/li>\n<li>Activate 3D acceleration (do not check 2D acceleration)<\/li>\n<li>CD Drive IDE type PIIX4 with E\/S<\/li>\n<li>Storage SATA AHCI without E\/S<\/li>\n<\/ul>\n<h1>Installing Linux Mint<\/h1>\n<p>Add the Linux iso as the CD Drive then start the machine. Once booted, double click on the &quot;Install Linux Mint&quot; CD icon then follow instructions.<\/p>\n<p>Once it reboots, press ENTER to continue, then create name\/username\/account. Once logged in, dismiss the welcome dialog box (you will address these points later if you want).<\/p>\n<p>The <em>first<\/em> thing you should do after that is to run<\/p>\n<pre><code class=\"language-bash\">apt-get update<\/code><\/pre>\n<p>in the terminal.<\/p>\n<p>Next, run<\/p>\n<pre><code class=\"language-bash\">apt-get install virtualbox-guest-dkms<\/code><\/pre>\n<p>Once done, click the &quot;Devices &gt; Insert guest addtions CD image&quot; menu in VirtualBox. Wait a minute while it does its thing.<\/p>\n<p>Then run these commands:<\/p>\n<pre><code class=\"language-bash\">sudo mount -t iso9660 \/dev\/sr0 \/mnt\nsudo apt install -y gcc make perl linux-headers-generic\nsudo sh \/mnt\/VBoxLinuxAdditions.run\nreboot<\/code><\/pre>\n<p>After reboot you should be able to resize the screen window and to properly run the VM on hidpi screens.<\/p>\n<h1>Installing VSCode and Swift<\/h1>\n<p>Try running this command:<\/p>\n<pre><code class=\"language-bash\">sudo apt install code<\/code><\/pre>\n<p>If it doesn't work, follow the detailed instructions specified on <a href=\"https:\/\/code.visualstudio.com\/docs\/setup\/linux\">VSCode Linux Install<\/a>.<\/p>\n<p>Install the missing bits:<\/p>\n<pre><code class=\"language-bash\">sudo apt install curl git clang libicu-dev libsqlite3-dev libblocksruntime-dev libncurses5-dev<\/code><\/pre>\n<p>Next, download Swift itself on swift.org. <\/p>\n<p>I used <a href=\"https:\/\/swift.org\/builds\/swift-5.1.4-release\/ubuntu1804\/swift-5.1.4-RELEASE\/swift-5.1.4-RELEASE-ubuntu18.04.tar.gz\">Swift 5.1.4<\/a>. If you're using a different version, you will have to adapt the path accordingly in the rest of this tutorial.<\/p>\n<p>Untar and install in the right place:<\/p>\n<pre><code class=\"language-bash\">sudo tar xzf swift-5.1.4-RELEASE-ubuntu18.04.tar.gz -C \/usr\/local\/bin<\/code><\/pre>\n<p>Add Swift to the command line path by adding this line at the <em>end<\/em> of your ~\/.bashrc file:<\/p>\n<pre><code class=\"language-bash\">export PATH=\/usr\/local\/bin\/swift-5.1.4-RELEASE-ubuntu18.04\/usr\/bin:&quot;${PATH}&quot;<\/code><\/pre>\n<p>Reload the command line session then run:<\/p>\n<pre><code class=\"language-bash\">swift --version<\/code><\/pre>\n<p>to make sure Swift was downloaded and installed correctly.<\/p>\n<h1>Installing SourceKit for VSCode<\/h1>\n<p>In order to properly use Swift in VSCode you need to build an extension based on sourcekit.<\/p>\n<p>Run these commands (the building step might take some time):<\/p>\n<pre><code class=\"language-bash\">git clone https:\/\/www.github.com\/apple\/sourcekit-lsp.git\ncd sourcekit-lsp\nswift package update\nswift build -Xcxx -I\/usr\/local\/bin\/swift-5.1.4-RELEASE-ubuntu18.04\/usr\/lib\/swift<\/code><\/pre>\n<p>Move the resulting build to the right place:<\/p>\n<pre><code class=\"language-bash\">sudo mv .build\/x86_64-unknown-linux\/debug\/sourcekit-lsp \/usr\/local\/bin<\/code><\/pre>\n<p>Install Node.js 12.x:<\/p>\n<pre><code class=\"language-bash\">curl -sL https:\/\/deb.nodesource.com\/setup_12.x | sudo -E bash -\nsudo apt-get install -y nodejs<\/code><\/pre>\n<p>Generate the extension for VSCode:<\/p>\n<pre><code class=\"language-bash\">cd Editors\/vscode\nnpm run createDevPackage<\/code><\/pre>\n<p>Install the extension:<\/p>\n<pre><code class=\"language-bash\">code --install-extension out\/sourcekit-lsp-vscode-dev.vsix<\/code><\/pre>\n<p>Launch VSCode then point sourcekit-lsp at your installed toolchain in VSCode\u2019s settings.<\/p>\n<p>Do &quot;File &gt; Preferences &gt; Settings&quot; then type settings.json in the search field. <\/p>\n<p>Click &quot;Edit JSON&quot; then add this between the curly barckets:<\/p>\n<pre><code class=\"language-text\">&quot;sourcekit-lsp.toolchainPath&quot;: &quot;\/usr\/local\/bin\/swift-5.1.4-RELEASE-ubuntu18.04\/&quot;<\/code><\/pre>\n<p>Save the file then reload your VSCode window (Control+Shift+P &gt; Reload Window) or restart VSCode.<\/p>\n<p>Done!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Getting VSCode on Linux Mint to properly run Swift with sourcekit-lsp in order to get syntax highlighting and code completion can be rather convoluted. Here&rsquo;s how I did it. First steps Download and install VirtualBox 6.0. Download Linux Mint Xfce 19.3. In VirtualBox, create a new virtual machine with these settings: Dynamic VDI disk, at&hellip; <a class=\"more-link\" href=\"https:\/\/www.aya.io\/blog\/swift-5-in-vscode-in-linux-mint-in-virtualbox\/\">Poursuivre la lecture <span class=\"screen-reader-text\">Swift 5 in VSCode in Linux Mint in VirtualBox<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":57,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,15,6],"tags":[21],"class_list":["post-56","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","category-linux","category-swift","tag-english","entry"],"_links":{"self":[{"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/posts\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/comments?post=56"}],"version-history":[{"count":4,"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/posts\/56\/revisions"}],"predecessor-version":[{"id":165,"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/posts\/56\/revisions\/165"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/media\/57"}],"wp:attachment":[{"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/media?parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/categories?post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aya.io\/blog\/wp-json\/wp\/v2\/tags?post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}