Compile and Run commands for swift












1















I want to compile and run swift language programs on Ubuntu 18.04.2 LTS, but I don't know the commands.
Please Help.










share|improve this question



























    1















    I want to compile and run swift language programs on Ubuntu 18.04.2 LTS, but I don't know the commands.
    Please Help.










    share|improve this question

























      1












      1








      1








      I want to compile and run swift language programs on Ubuntu 18.04.2 LTS, but I don't know the commands.
      Please Help.










      share|improve this question














      I want to compile and run swift language programs on Ubuntu 18.04.2 LTS, but I don't know the commands.
      Please Help.







      language






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 19 at 11:25









      Naman Naman

      62




      62






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Open the terminal and type:



          sudo apt install clang libicu-dev -y
          wget https://swift.org/builds/swift-4.2.3-release/ubuntu1804/swift-4.2.3-RELEASE/swift-4.2.3-RELEASE-ubuntu18.04.tar.gz
          mkdir ~/swift
          tar -xvzf swift-4.2.3-RELEASE-ubuntu18.04.tar.gz -C ~/swift
          nano ~/.bashrc


          .bashrc will open in the terminal for editing in nano text editor. Paste the following line at the end of .bashrc.



          export PATH=~/swift/swift-4.2.3-RELEASE-ubuntu18.04/usr/bin:$PATH


          Press the keyboard combination Ctrl+O and after that press Enter to save the file being edited. Press the keyboard combination Ctrl+X to exit nano.



          Close the terminal, open a new terminal, and run the following commands.



          swift -version # This command should print Swift version 4.2.3.
          cd Desktop/
          mkdir helloworld-project && cd helloworld-project
          swift package init --type executable
          swift build
          .build/debug/helloworld-project


          Results:



          Hello, world!


          Swift REPL example 1



          Swift has an interactive interpreter called the REPL which stands for Read-Eval-Print-Loop. The REPL can be run interactively from the command line as demonstrated in the below example.



          $ swift -repl
          :0: warning: unnecessary option '-repl'; this is the default for 'swift'
          with no input files

          Welcome to Swift version 4.2.3 (swift-4.2.3-RELEASE). Type :help for assistance.
          1> // Hello, World! Program
          2> import Swift
          3> print("Hello, World!")
          Hello, World!
          4> :exit


          Swift REPL example 2



          This example executes the same code as example 1 with two differences.




          1. Everything is done in Gedit.

          2. The entire code block is copy/pasted from the edit pane into the terminal pane in Gedit (Embedded Terminal plugin), and run by the Swift interpreter as a block of code instead of one line at a time.


          enter image description here






          share|improve this answer


























          • Thank You for your answer. Your answer helped me go to the swift shell and work upon that. However, the requirement is of the commands that can simply compile and then run the swift program written in a text editor like that in 'gedit'. Unlikely, the answer tells how to work upon the shell itself and not on the text editor.

            – Naman
            Mar 20 at 13:48











          • I added a screenshot of running an entire Swift program in Gedit using the built-in Gedit terminal..

            – karel
            Mar 20 at 14:14











          • Thank You for your constant help, friend. But still the commands for compiling and running are missing. The following set of steps is what I want to follow in the terminal: (1) gedit fileName.swift (2) *swift program compiling command. (3) *swift program running command. ________After this, the output should be visible at the terminal.

            – Naman
            Mar 20 at 16:42











          • That's not Gedit or any text editor. That sequence is called an IDE, like Xcode (which stands for "execute code").

            – karel
            Mar 20 at 16:53












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1126916%2fcompile-and-run-commands-for-swift%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Open the terminal and type:



          sudo apt install clang libicu-dev -y
          wget https://swift.org/builds/swift-4.2.3-release/ubuntu1804/swift-4.2.3-RELEASE/swift-4.2.3-RELEASE-ubuntu18.04.tar.gz
          mkdir ~/swift
          tar -xvzf swift-4.2.3-RELEASE-ubuntu18.04.tar.gz -C ~/swift
          nano ~/.bashrc


          .bashrc will open in the terminal for editing in nano text editor. Paste the following line at the end of .bashrc.



          export PATH=~/swift/swift-4.2.3-RELEASE-ubuntu18.04/usr/bin:$PATH


          Press the keyboard combination Ctrl+O and after that press Enter to save the file being edited. Press the keyboard combination Ctrl+X to exit nano.



          Close the terminal, open a new terminal, and run the following commands.



          swift -version # This command should print Swift version 4.2.3.
          cd Desktop/
          mkdir helloworld-project && cd helloworld-project
          swift package init --type executable
          swift build
          .build/debug/helloworld-project


          Results:



          Hello, world!


          Swift REPL example 1



          Swift has an interactive interpreter called the REPL which stands for Read-Eval-Print-Loop. The REPL can be run interactively from the command line as demonstrated in the below example.



          $ swift -repl
          :0: warning: unnecessary option '-repl'; this is the default for 'swift'
          with no input files

          Welcome to Swift version 4.2.3 (swift-4.2.3-RELEASE). Type :help for assistance.
          1> // Hello, World! Program
          2> import Swift
          3> print("Hello, World!")
          Hello, World!
          4> :exit


          Swift REPL example 2



          This example executes the same code as example 1 with two differences.




          1. Everything is done in Gedit.

          2. The entire code block is copy/pasted from the edit pane into the terminal pane in Gedit (Embedded Terminal plugin), and run by the Swift interpreter as a block of code instead of one line at a time.


          enter image description here






          share|improve this answer


























          • Thank You for your answer. Your answer helped me go to the swift shell and work upon that. However, the requirement is of the commands that can simply compile and then run the swift program written in a text editor like that in 'gedit'. Unlikely, the answer tells how to work upon the shell itself and not on the text editor.

            – Naman
            Mar 20 at 13:48











          • I added a screenshot of running an entire Swift program in Gedit using the built-in Gedit terminal..

            – karel
            Mar 20 at 14:14











          • Thank You for your constant help, friend. But still the commands for compiling and running are missing. The following set of steps is what I want to follow in the terminal: (1) gedit fileName.swift (2) *swift program compiling command. (3) *swift program running command. ________After this, the output should be visible at the terminal.

            – Naman
            Mar 20 at 16:42











          • That's not Gedit or any text editor. That sequence is called an IDE, like Xcode (which stands for "execute code").

            – karel
            Mar 20 at 16:53
















          2














          Open the terminal and type:



          sudo apt install clang libicu-dev -y
          wget https://swift.org/builds/swift-4.2.3-release/ubuntu1804/swift-4.2.3-RELEASE/swift-4.2.3-RELEASE-ubuntu18.04.tar.gz
          mkdir ~/swift
          tar -xvzf swift-4.2.3-RELEASE-ubuntu18.04.tar.gz -C ~/swift
          nano ~/.bashrc


          .bashrc will open in the terminal for editing in nano text editor. Paste the following line at the end of .bashrc.



          export PATH=~/swift/swift-4.2.3-RELEASE-ubuntu18.04/usr/bin:$PATH


          Press the keyboard combination Ctrl+O and after that press Enter to save the file being edited. Press the keyboard combination Ctrl+X to exit nano.



          Close the terminal, open a new terminal, and run the following commands.



          swift -version # This command should print Swift version 4.2.3.
          cd Desktop/
          mkdir helloworld-project && cd helloworld-project
          swift package init --type executable
          swift build
          .build/debug/helloworld-project


          Results:



          Hello, world!


          Swift REPL example 1



          Swift has an interactive interpreter called the REPL which stands for Read-Eval-Print-Loop. The REPL can be run interactively from the command line as demonstrated in the below example.



          $ swift -repl
          :0: warning: unnecessary option '-repl'; this is the default for 'swift'
          with no input files

          Welcome to Swift version 4.2.3 (swift-4.2.3-RELEASE). Type :help for assistance.
          1> // Hello, World! Program
          2> import Swift
          3> print("Hello, World!")
          Hello, World!
          4> :exit


          Swift REPL example 2



          This example executes the same code as example 1 with two differences.




          1. Everything is done in Gedit.

          2. The entire code block is copy/pasted from the edit pane into the terminal pane in Gedit (Embedded Terminal plugin), and run by the Swift interpreter as a block of code instead of one line at a time.


          enter image description here






          share|improve this answer


























          • Thank You for your answer. Your answer helped me go to the swift shell and work upon that. However, the requirement is of the commands that can simply compile and then run the swift program written in a text editor like that in 'gedit'. Unlikely, the answer tells how to work upon the shell itself and not on the text editor.

            – Naman
            Mar 20 at 13:48











          • I added a screenshot of running an entire Swift program in Gedit using the built-in Gedit terminal..

            – karel
            Mar 20 at 14:14











          • Thank You for your constant help, friend. But still the commands for compiling and running are missing. The following set of steps is what I want to follow in the terminal: (1) gedit fileName.swift (2) *swift program compiling command. (3) *swift program running command. ________After this, the output should be visible at the terminal.

            – Naman
            Mar 20 at 16:42











          • That's not Gedit or any text editor. That sequence is called an IDE, like Xcode (which stands for "execute code").

            – karel
            Mar 20 at 16:53














          2












          2








          2







          Open the terminal and type:



          sudo apt install clang libicu-dev -y
          wget https://swift.org/builds/swift-4.2.3-release/ubuntu1804/swift-4.2.3-RELEASE/swift-4.2.3-RELEASE-ubuntu18.04.tar.gz
          mkdir ~/swift
          tar -xvzf swift-4.2.3-RELEASE-ubuntu18.04.tar.gz -C ~/swift
          nano ~/.bashrc


          .bashrc will open in the terminal for editing in nano text editor. Paste the following line at the end of .bashrc.



          export PATH=~/swift/swift-4.2.3-RELEASE-ubuntu18.04/usr/bin:$PATH


          Press the keyboard combination Ctrl+O and after that press Enter to save the file being edited. Press the keyboard combination Ctrl+X to exit nano.



          Close the terminal, open a new terminal, and run the following commands.



          swift -version # This command should print Swift version 4.2.3.
          cd Desktop/
          mkdir helloworld-project && cd helloworld-project
          swift package init --type executable
          swift build
          .build/debug/helloworld-project


          Results:



          Hello, world!


          Swift REPL example 1



          Swift has an interactive interpreter called the REPL which stands for Read-Eval-Print-Loop. The REPL can be run interactively from the command line as demonstrated in the below example.



          $ swift -repl
          :0: warning: unnecessary option '-repl'; this is the default for 'swift'
          with no input files

          Welcome to Swift version 4.2.3 (swift-4.2.3-RELEASE). Type :help for assistance.
          1> // Hello, World! Program
          2> import Swift
          3> print("Hello, World!")
          Hello, World!
          4> :exit


          Swift REPL example 2



          This example executes the same code as example 1 with two differences.




          1. Everything is done in Gedit.

          2. The entire code block is copy/pasted from the edit pane into the terminal pane in Gedit (Embedded Terminal plugin), and run by the Swift interpreter as a block of code instead of one line at a time.


          enter image description here






          share|improve this answer















          Open the terminal and type:



          sudo apt install clang libicu-dev -y
          wget https://swift.org/builds/swift-4.2.3-release/ubuntu1804/swift-4.2.3-RELEASE/swift-4.2.3-RELEASE-ubuntu18.04.tar.gz
          mkdir ~/swift
          tar -xvzf swift-4.2.3-RELEASE-ubuntu18.04.tar.gz -C ~/swift
          nano ~/.bashrc


          .bashrc will open in the terminal for editing in nano text editor. Paste the following line at the end of .bashrc.



          export PATH=~/swift/swift-4.2.3-RELEASE-ubuntu18.04/usr/bin:$PATH


          Press the keyboard combination Ctrl+O and after that press Enter to save the file being edited. Press the keyboard combination Ctrl+X to exit nano.



          Close the terminal, open a new terminal, and run the following commands.



          swift -version # This command should print Swift version 4.2.3.
          cd Desktop/
          mkdir helloworld-project && cd helloworld-project
          swift package init --type executable
          swift build
          .build/debug/helloworld-project


          Results:



          Hello, world!


          Swift REPL example 1



          Swift has an interactive interpreter called the REPL which stands for Read-Eval-Print-Loop. The REPL can be run interactively from the command line as demonstrated in the below example.



          $ swift -repl
          :0: warning: unnecessary option '-repl'; this is the default for 'swift'
          with no input files

          Welcome to Swift version 4.2.3 (swift-4.2.3-RELEASE). Type :help for assistance.
          1> // Hello, World! Program
          2> import Swift
          3> print("Hello, World!")
          Hello, World!
          4> :exit


          Swift REPL example 2



          This example executes the same code as example 1 with two differences.




          1. Everything is done in Gedit.

          2. The entire code block is copy/pasted from the edit pane into the terminal pane in Gedit (Embedded Terminal plugin), and run by the Swift interpreter as a block of code instead of one line at a time.


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 20 at 14:13

























          answered Mar 19 at 12:27









          karelkarel

          60.6k13132155




          60.6k13132155













          • Thank You for your answer. Your answer helped me go to the swift shell and work upon that. However, the requirement is of the commands that can simply compile and then run the swift program written in a text editor like that in 'gedit'. Unlikely, the answer tells how to work upon the shell itself and not on the text editor.

            – Naman
            Mar 20 at 13:48











          • I added a screenshot of running an entire Swift program in Gedit using the built-in Gedit terminal..

            – karel
            Mar 20 at 14:14











          • Thank You for your constant help, friend. But still the commands for compiling and running are missing. The following set of steps is what I want to follow in the terminal: (1) gedit fileName.swift (2) *swift program compiling command. (3) *swift program running command. ________After this, the output should be visible at the terminal.

            – Naman
            Mar 20 at 16:42











          • That's not Gedit or any text editor. That sequence is called an IDE, like Xcode (which stands for "execute code").

            – karel
            Mar 20 at 16:53



















          • Thank You for your answer. Your answer helped me go to the swift shell and work upon that. However, the requirement is of the commands that can simply compile and then run the swift program written in a text editor like that in 'gedit'. Unlikely, the answer tells how to work upon the shell itself and not on the text editor.

            – Naman
            Mar 20 at 13:48











          • I added a screenshot of running an entire Swift program in Gedit using the built-in Gedit terminal..

            – karel
            Mar 20 at 14:14











          • Thank You for your constant help, friend. But still the commands for compiling and running are missing. The following set of steps is what I want to follow in the terminal: (1) gedit fileName.swift (2) *swift program compiling command. (3) *swift program running command. ________After this, the output should be visible at the terminal.

            – Naman
            Mar 20 at 16:42











          • That's not Gedit or any text editor. That sequence is called an IDE, like Xcode (which stands for "execute code").

            – karel
            Mar 20 at 16:53

















          Thank You for your answer. Your answer helped me go to the swift shell and work upon that. However, the requirement is of the commands that can simply compile and then run the swift program written in a text editor like that in 'gedit'. Unlikely, the answer tells how to work upon the shell itself and not on the text editor.

          – Naman
          Mar 20 at 13:48





          Thank You for your answer. Your answer helped me go to the swift shell and work upon that. However, the requirement is of the commands that can simply compile and then run the swift program written in a text editor like that in 'gedit'. Unlikely, the answer tells how to work upon the shell itself and not on the text editor.

          – Naman
          Mar 20 at 13:48













          I added a screenshot of running an entire Swift program in Gedit using the built-in Gedit terminal..

          – karel
          Mar 20 at 14:14





          I added a screenshot of running an entire Swift program in Gedit using the built-in Gedit terminal..

          – karel
          Mar 20 at 14:14













          Thank You for your constant help, friend. But still the commands for compiling and running are missing. The following set of steps is what I want to follow in the terminal: (1) gedit fileName.swift (2) *swift program compiling command. (3) *swift program running command. ________After this, the output should be visible at the terminal.

          – Naman
          Mar 20 at 16:42





          Thank You for your constant help, friend. But still the commands for compiling and running are missing. The following set of steps is what I want to follow in the terminal: (1) gedit fileName.swift (2) *swift program compiling command. (3) *swift program running command. ________After this, the output should be visible at the terminal.

          – Naman
          Mar 20 at 16:42













          That's not Gedit or any text editor. That sequence is called an IDE, like Xcode (which stands for "execute code").

          – karel
          Mar 20 at 16:53





          That's not Gedit or any text editor. That sequence is called an IDE, like Xcode (which stands for "execute code").

          – karel
          Mar 20 at 16:53


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Ask Ubuntu!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1126916%2fcompile-and-run-commands-for-swift%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          數位音樂下載

          When can things happen in Etherscan, such as the picture below?

          格利澤436b