Difference between revisions of "Rust/C2/Installation-of-Rust-on-Linux/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
Author: Jayesh Katta Ramalingaiah
 
Author: Jayesh Katta Ramalingaiah
  
Domain Reviewer:  
+
Domain Reviewer: Vigneshwer Dhinakaran
  
 
Novice Reviewer: Praveen S
 
Novice Reviewer: Praveen S
  
 
Keywords: Rust, version, rustc, cargo, rustup
 
Keywords: Rust, version, rustc, cargo, rustup
 
  
  
Line 18: Line 17:
 
|| Slide: Title
 
|| Slide: Title
 
|| Welcome to the spoken tutorial on '''Installation of Rust on Linux OS'''.
 
|| Welcome to the spoken tutorial on '''Installation of Rust on Linux OS'''.
 
 
|-
 
|-
 
|| Slide:  
 
|| Slide:  
Line 24: Line 22:
 
Learning Objectives
 
Learning Objectives
 
|| In this tutorial, we will learn:
 
|| In this tutorial, we will learn:
 
 
 
* How to install '''Rust'''.  
 
* How to install '''Rust'''.  
 
* Create and execute a '''Rust''' file
 
* Create and execute a '''Rust''' file
 
 
 
 
|-
 
|-
 
|| Slide: System Specifications
 
|| Slide: System Specifications
 
|| This tutorial is recorded using:
 
|| This tutorial is recorded using:
 
 
* '''Ubuntu Linux''' OS version 18.04
 
* '''Ubuntu Linux''' OS version 18.04
 
* '''Rust''' version 1.47.0
 
* '''Rust''' version 1.47.0
Line 40: Line 32:
  
 
However you may use any other editor of your choice.
 
However you may use any other editor of your choice.
 
 
|-
 
|-
 
|| Slide: Pre-requisites
 
|| Slide: Pre-requisites
Line 48: Line 39:
 
* You should be familiar with basic '''Linux commands.'''
 
* You should be familiar with basic '''Linux commands.'''
 
* If not, please go through the prerequisite '''Linux''' tutorials on this website.
 
* If not, please go through the prerequisite '''Linux''' tutorials on this website.
 
 
 
 
|-
 
|-
 
|| Slide: Code files
 
|| Slide: Code files
 
||  
 
||  
 
* The files used in this tutorial are available in the''' Code files''' link on this tutorial page.
 
* The files used in this tutorial are available in the''' Code files''' link on this tutorial page.
* Pls download and extract the file.
+
* Pls download and extract the files.
* Make a copy and then use it for practising.
+
* Make a copy and then use them for practising.
 
+
 
+
 
+
 
|-
 
|-
 
|| Only narration
 
|| Only narration
 
|| Let us begin with the installation of '''Rust'''.
 
|| Let us begin with the installation of '''Rust'''.
 
 
|-
 
|-
 
|| Show '''commands.txt''' in text editor  
 
|| Show '''commands.txt''' in text editor  
 
|| I have opened the '''Commands.txt '''file in a '''text editor '''on my machine.
 
|| I have opened the '''Commands.txt '''file in a '''text editor '''on my machine.
 
  
 
And I will use the same file to copy-paste the '''commands''' during the demonstration.
 
And I will use the same file to copy-paste the '''commands''' during the demonstration.
 
  
 
Shortcut to paste '''commands''' on the '''terminal''' is '''Shift, Ctrl '''and '''V '''keys'''.'''
 
Shortcut to paste '''commands''' on the '''terminal''' is '''Shift, Ctrl '''and '''V '''keys'''.'''
 
 
|-
 
|-
 
|| Narration only
 
|| Narration only
 
|| Let us begin.
 
|| Let us begin.
 
 
|-
 
|-
 
|| Press '''Ctrl+Alt+T '''keys
 
|| Press '''Ctrl+Alt+T '''keys
 
|| Open the '''terminal''' by pressing '''Ctrl,Alt''' and '''T''' keys simultaneously on the keyboard.
 
|| Open the '''terminal''' by pressing '''Ctrl,Alt''' and '''T''' keys simultaneously on the keyboard.
 
  
 
Ensure that you have '''root permissions''' to '''run''' the '''commands'''.
 
Ensure that you have '''root permissions''' to '''run''' the '''commands'''.
 
 
|-
 
|-
 
|| Only Narration
 
|| Only Narration
 
|| Here onwards, please remember to press the '''Enter''' key after typing each '''command'''.
 
|| Here onwards, please remember to press the '''Enter''' key after typing each '''command'''.
 
 
|-
 
|-
 
|| <nowiki>[Terminal]</nowiki>
 
|| <nowiki>[Terminal]</nowiki>
 
  
 
Type:  
 
Type:  
Line 100: Line 76:
 
|| We will be installing '''Rust''' with the help of the '''curl command line tool.'''
 
|| We will be installing '''Rust''' with the help of the '''curl command line tool.'''
  
 
+
So, we have to first '''install curl''' if we haven’t done so earlier.
So, we have to first install '''curl''' if we haven’t done so earlier.
+
 
+
  
 
To do so type the '''command''' as shown on the '''terminal'''.
 
To do so type the '''command''' as shown on the '''terminal'''.
 
 
|-
 
|-
 
|| <nowiki>[Terminal] </nowiki>
 
|| <nowiki>[Terminal] </nowiki>
  
 
Enter admin password
 
Enter admin password
|| If prompted enter the '''admin password''' to proceed further.
+
|| If '''prompted''', enter the '''admin password''' to proceed further.
 
+
 
|-
 
|-
 
|| <nowiki>[Terminal] Type:</nowiki>
 
|| <nowiki>[Terminal] Type:</nowiki>
 
  
 
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
 
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
  
 
<nowiki>[Enter]</nowiki>
 
<nowiki>[Enter]</nowiki>
|| We have successfully installed '''curl'''.
+
|| We have successfully '''installed curl'''.
 
+
 
+
Next let us download and install '''Rust''' using '''Curl'''.
+
  
 +
Next let us download and '''install Rust''' using '''Curl'''.
  
 
To do so type the '''command''' as shown on the '''terminal'''.
 
To do so type the '''command''' as shown on the '''terminal'''.
 
 
|-
 
|-
 
|| Only Narration
 
|| Only Narration
 
|| The download may take some time depending upon your '''internet speed.'''
 
|| The download may take some time depending upon your '''internet speed.'''
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Highlight one by one:</nowiki>
 
|| <nowiki>[Terminal] Highlight one by one:</nowiki>
 
  
 
Proceed with installation (default)
 
Proceed with installation (default)
Line 140: Line 106:
  
 
Cancel installation
 
Cancel installation
|| Once the '''package''' is downloaded, we will be prompted to choose one of the following options:
+
|| Once the '''package''' is downloaded, we will be '''prompted''' to choose one of the following options:
 
+
  
 
'''Proceed with installation (default)'''
 
'''Proceed with installation (default)'''
 
  
 
'''Customize installation'''
 
'''Customize installation'''
 
  
 
'''Cancel installation'''
 
'''Cancel installation'''
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Type: </nowiki><nowiki>1 [Enter]</nowiki>
 
|| <nowiki>[Terminal] Type: </nowiki><nowiki>1 [Enter]</nowiki>
|| To proceed with the default '''installation''', type '''1''' and press '''Enter'''.
+
|| To proceed with default '''installation''', type '''1''' and press '''Enter'''.
 
+
 
|-
 
|-
 
|| <nowiki>[Terminal] Highlight:</nowiki>
 
|| <nowiki>[Terminal] Highlight:</nowiki>
Line 160: Line 121:
 
Rust is installed now. Great!
 
Rust is installed now. Great!
 
|| We have successfully installed '''Rust'''.
 
|| We have successfully installed '''Rust'''.
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Type:</nowiki>
 
|| <nowiki>[Terminal] Type:</nowiki>
 
  
 
'''sudo reboot '''<nowiki>[Enter]</nowiki>
 
'''sudo reboot '''<nowiki>[Enter]</nowiki>
 
|| Once the installation is done, we need to restart our computer.
 
|| Once the installation is done, we need to restart our computer.
 
  
 
To do so, type '''sudo reboot''' in the '''terminal'''.
 
To do so, type '''sudo reboot''' in the '''terminal'''.
 
  
 
This will restart your computer.
 
This will restart your computer.
 
 
|-
 
|-
 
|| Press '''Ctrl+Alt+T '''keys
 
|| Press '''Ctrl+Alt+T '''keys
|| Once you have restarted the computer, open the terminal again
+
|| Once you have restarted the computer, open the '''terminal''' again.
 
+
 
|-
 
|-
 
|| <nowiki>[Terminal] Type:</nowiki>
 
|| <nowiki>[Terminal] Type:</nowiki>
 
  
 
<nowiki>rustc --version [Enter]</nowiki>
 
<nowiki>rustc --version [Enter]</nowiki>
|| Now let us cross verify the '''Rust''' installation.
+
|| Now let us cross verify the '''Rust installation'''.
 
+
  
 
Type the '''command''' as shown in the '''terminal'''.
 
Type the '''command''' as shown in the '''terminal'''.
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Highlight:</nowiki>
 
|| <nowiki>[Terminal] Highlight:</nowiki>
Line 193: Line 145:
 
rustc 1.47.0
 
rustc 1.47.0
 
|| This '''command''' shows the version of '''Rust''' installed in your computer.
 
|| This '''command''' shows the version of '''Rust''' installed in your computer.
 
  
 
The '''version''' number may be different in your case.
 
The '''version''' number may be different in your case.
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Type: </nowiki>
 
|| <nowiki>[Terminal] Type: </nowiki>
Line 202: Line 152:
 
<nowiki>rustup [Enter] </nowiki>
 
<nowiki>rustup [Enter] </nowiki>
 
|| Now type '''rustup''' on the '''terminal.'''
 
|| Now type '''rustup''' on the '''terminal.'''
 
 
|-
 
|-
 
|| Only narration  
 
|| Only narration  
|| This shows us a list of '''Rust commands''' to '''run'''.
+
|| This shows us a list of '''commands''' to '''run'''.
 
+
  
 
'''rustup''' is responsible for the complete '''Rust installation''' using the '''curl command.'''
 
'''rustup''' is responsible for the complete '''Rust installation''' using the '''curl command.'''
 
 
|-
 
|-
 
|| Slide: Rust Update
 
|| Slide: Rust Update
 
  
 
<nowiki>rustup update [Enter]</nowiki>
 
<nowiki>rustup update [Enter]</nowiki>
 
|| If you wish to update your '''Rust''' version, then execute this '''command''' on the '''terminal'''.
 
|| If you wish to update your '''Rust''' version, then execute this '''command''' on the '''terminal'''.
 
 
|-
 
|-
 
|| Slide: rustup toolchain list
 
|| Slide: rustup toolchain list
 
|| '''rustup toolchain command''' lists the various '''toolchains''' of '''Rust''' installed in your machine.
 
|| '''rustup toolchain command''' lists the various '''toolchains''' of '''Rust''' installed in your machine.
 
  
 
For now, I have only one stable version installed.  
 
For now, I have only one stable version installed.  
 
  
 
If you have any other versions, then that version would be displayed.
 
If you have any other versions, then that version would be displayed.
 
 
|-
 
|-
 
|| Slide: cargo
 
|| Slide: cargo
 
|| '''cargo''' is a '''package manager''' to maintain a '''Rust project''' with '''dependencies'''.  
 
|| '''cargo''' is a '''package manager''' to maintain a '''Rust project''' with '''dependencies'''.  
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Type:</nowiki>
 
|| <nowiki>[Terminal] Type:</nowiki>
 
  
 
<nowiki>cargo [Enter]</nowiki>
 
<nowiki>cargo [Enter]</nowiki>
|| You can check whether '''cargo''' is installed or not using the '''cargo command''' in the '''terminal.'''
+
|| You can check whether '''cargo''' is '''installed''' or not using the '''cargo command''' in the '''terminal.'''
 
+
  
 
This shows a list of '''commands''' which can be executed using '''cargo'''.
 
This shows a list of '''commands''' which can be executed using '''cargo'''.
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Type:</nowiki>
 
|| <nowiki>[Terminal] Type:</nowiki>
  
 
cargo <nowiki>--version [Enter] </nowiki>
 
cargo <nowiki>--version [Enter] </nowiki>
|| This '''command''' shows the '''version''' of the '''cargo package manager''' installed in your machine.
+
|| This '''command''' shows the '''version''' of the '''cargo package manager installed''' in your machine.
 
+
 
|-
 
|-
 
|| Slide: Common Errors After Installation
 
|| Slide: Common Errors After Installation
||  
+
|| Common Errors After '''Installation'''
 
* '''System restart''' is required after '''installing rust'''.
 
* '''System restart''' is required after '''installing rust'''.
 
* If not, we could land with these errors
 
* If not, we could land with these errors
Line 255: Line 192:
 
** '''Rustc'''
 
** '''Rustc'''
 
** '''Cargo - command not found'''
 
** '''Cargo - command not found'''
 
 
 
 
|-
 
|-
 
|| Only narration
 
|| Only narration
|| Next let us learn how to create and execute a '''Rust''' file.
+
|| Next let us learn how to create and '''execute''' a '''Rust''' file.
 
+
 
|-
 
|-
 
|| Open Visual Studio Code editor.
 
|| Open Visual Studio Code editor.
 
|| You may use any '''editor''' of your choice.
 
|| You may use any '''editor''' of your choice.
 
  
 
I will use '''Visual Studio Code editor '''for this demonstration'''.'''
 
I will use '''Visual Studio Code editor '''for this demonstration'''.'''
 
 
|-
 
|-
 
|| <nowiki>[Editor] Type:</nowiki>
 
|| <nowiki>[Editor] Type:</nowiki>
 
  
 
fn main() {
 
fn main() {
Line 278: Line 208:
  
 
}
 
}
|| In the '''code''' editor, type the code as shown.
+
|| In the '''code editor''', type the code as shown.
 
+
 
|-
 
|-
 
|| <nowiki>[Editor] </nowiki>Highlight:  
 
|| <nowiki>[Editor] </nowiki>Highlight:  
Line 287: Line 216:
 
'''}'''
 
'''}'''
 
|| This is our '''main function.'''  
 
|| This is our '''main function.'''  
 
 
|-
 
|-
 
|| <nowiki>[Editor] </nowiki>Highlight: '''fn '''
 
|| <nowiki>[Editor] </nowiki>Highlight: '''fn '''
|| The '''keyword - fn''' is used as a '''syntax''' to create a '''function''' in '''Rust'''.
+
|| The '''keyword fn''' is used as a '''syntax''' to create a '''function''' in '''Rust'''.
 
+
 
|-
 
|-
 
|| <nowiki>[Editor] </nowiki>Highlight: '''main()'''
 
|| <nowiki>[Editor] </nowiki>Highlight: '''main()'''
 
|| '''main''' indicated the name of the '''function'''.  
 
|| '''main''' indicated the name of the '''function'''.  
 
  
 
The '''Rust execution''' starts from the '''main function.'''
 
The '''Rust execution''' starts from the '''main function.'''
 
 
|-
 
|-
 
|| <nowiki>[Editor] </nowiki>Highlight:  
 
|| <nowiki>[Editor] </nowiki>Highlight:  
Line 306: Line 231:
 
'''}'''
 
'''}'''
 
|| The code written in between the '''open''' and '''closed curly braces''' would be the '''function body.'''
 
|| The code written in between the '''open''' and '''closed curly braces''' would be the '''function body.'''
 
 
|-
 
|-
 
|| <nowiki>[Editor] Highlight </nowiki>'''print!'''
 
|| <nowiki>[Editor] Highlight </nowiki>'''print!'''
 
|| '''Print!()''' is the '''print function''' in '''Rust'''.
 
|| '''Print!()''' is the '''print function''' in '''Rust'''.
 
 
|-
 
|-
 
|| <nowiki>[Editor] Highlight </nowiki>
 
|| <nowiki>[Editor] Highlight </nowiki>
  
 
'''Hello World'''
 
'''Hello World'''
|| Here we have written '''Hello World''' in double quotes as a '''parameter''' in the '''function''' '''call'''.
+
|| Here we have '''Hello World''' in double quotes as a '''parameter''' in the '''function call'''.
 
+
 
|-
 
|-
 
|| <nowiki>[Editor] Highlight </nowiki>
 
|| <nowiki>[Editor] Highlight </nowiki>
  
 
'''print!(“Hello World”)'''
 
'''print!(“Hello World”)'''
|| So, when we '''run''' the '''program''', '''hello world''' gets printed.
+
|| So, when we '''run''' the '''program''', '''Hello World''' gets printed.
 
+
 
|-
 
|-
 
|| Press Ctrl + S
 
|| Press Ctrl + S
 
|| Let us save the file by pressing '''Ctrl''' + '''S''' keys together.
 
|| Let us save the file by pressing '''Ctrl''' + '''S''' keys together.
 
 
|-
 
|-
 
|| Point to Save As dialog box
 
|| Point to Save As dialog box
 
|| '''Save''' dialog box opens.
 
|| '''Save''' dialog box opens.
 
+
|-
 +
|| Select '''Desktop''' on the left side
 +
|| Select '''Desktop''' location.
 
|-
 
|-
 
|| Point to Name >> type "hello-world.rs"
 
|| Point to Name >> type "hello-world.rs"
|| In the '''Name''' field type the name of the file as '''hello-world.rs'''
+
|| In the '''Name''' field, type the name of the file as '''hello-world.rs'''
 
+
 
|-
 
|-
 
|| Highlight .rs
 
|| Highlight .rs
 
|| The extension '''.rs''' states that this is a '''Rust code file'''.
 
|| The extension '''.rs''' states that this is a '''Rust code file'''.
 
 
|-
 
|-
|| Select '''Desktop''' location
+
|| Under '''Desktop''' >> Create '''MyRustProject '''folder
 
+
|| And then create a folder named '''MyRustProject.'''
 
+
Create '''MyRustProject '''folder
+
|| On the left side, I’ll select '''Desktop '''and then create a folder named '''MyRustProject.'''
+
 
+
 
|-
 
|-
 
|| Point to '''MyRustProject'''
 
|| Point to '''MyRustProject'''
 
|| From now on, I will be saving my '''Rust files''' in this folder.
 
|| From now on, I will be saving my '''Rust files''' in this folder.
 
 
|-
 
|-
 
|| Click on '''Save''' button.
 
|| Click on '''Save''' button.
|| Then click on the '''Save''' button at the top right corner of the dialog box.
+
|| Then click on the '''Save''' button on the top right corner of the dialog box.
 
+
 
|-
 
|-
 
||  
 
||  
|| We have created a '''Rust file''' and have written the '''hello world program'''.  
+
|| We have created a '''Rust file''' and have written the '''Hello World program'''.  
 
+
  
 
Now, it’s time to '''compile''' and '''run''' the '''file'''.
 
Now, it’s time to '''compile''' and '''run''' the '''file'''.
 
 
|-
 
|-
 
|| Switch to terminal
 
|| Switch to terminal
 
|| Switch back to the '''terminal.'''
 
|| Switch back to the '''terminal.'''
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Type:</nowiki>
 
|| <nowiki>[Terminal] Type:</nowiki>
 
  
 
cd Desktop/MyRustProject  
 
cd Desktop/MyRustProject  
Line 373: Line 283:
 
<nowiki>[Enter]</nowiki>
 
<nowiki>[Enter]</nowiki>
 
|| Using''' cd command''' go to the location where the '''Rust file '''is saved.
 
|| Using''' cd command''' go to the location where the '''Rust file '''is saved.
 
  
 
In my case, it is '''MyRustProject''' on the '''Desktop.'''
 
In my case, it is '''MyRustProject''' on the '''Desktop.'''
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Type:</nowiki>
 
|| <nowiki>[Terminal] Type:</nowiki>
 
  
 
<nowiki>rustc hello-world.rs [Enter]</nowiki>
 
<nowiki>rustc hello-world.rs [Enter]</nowiki>
|| To '''compile''' type '''rustc''' '''space''' filename with extension '''.rs'''
+
|| To '''compile,''' type '''rustc space filename''' with extension '''.rs'''
 
+
  
 
In my case it is '''hello-world.rs'''
 
In my case it is '''hello-world.rs'''
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Type:</nowiki>
 
|| <nowiki>[Terminal] Type:</nowiki>
 
  
 
<nowiki>./hello-world [Enter]</nowiki>
 
<nowiki>./hello-world [Enter]</nowiki>
 
|| The '''compilation''' is done without any error.
 
|| The '''compilation''' is done without any error.
 
  
 
Now, to '''run''' type the '''dot slash filename''' and press '''Enter'''.
 
Now, to '''run''' type the '''dot slash filename''' and press '''Enter'''.
 
  
 
In my case it is '''./hello-world'''
 
In my case it is '''./hello-world'''
 
 
|-
 
|-
 
|| <nowiki>[Terminal] Highlight: </nowiki>
 
|| <nowiki>[Terminal] Highlight: </nowiki>
Line 405: Line 306:
 
Hello World
 
Hello World
 
|| '''Hello world''' text gets printed.
 
|| '''Hello world''' text gets printed.
 
 
|-
 
|-
 
|| Slide: Common Errors
 
|| Slide: Common Errors
 
  
 
'''sudo apt install build-essential'''
 
'''sudo apt install build-essential'''
Line 414: Line 313:
 
* You could land up with this error while '''compiling - linker ‘cc’ not found. '''
 
* You could land up with this error while '''compiling - linker ‘cc’ not found. '''
 
* It means you don’t have '''gcc''' in your machine.
 
* It means you don’t have '''gcc''' in your machine.
* To resolve this, '''install''' the '''build''' '''essentials''' with this '''command'''.  
+
* To resolve this, '''install''' the '''build essentials''' with this '''command'''.  
 
+
 
+
 
+
 
|-
 
|-
 
|| Only narration
 
|| Only narration
 +
|| We have successfully '''installed Rust''' and executed the '''Hello World program'''.
  
 +
With this we have come to the end of this tutorial.
  
 
+
Let’s summarize.
|| We have successfully installed '''Rust''' and executed the '''hello world program'''.
+
 
+
 
+
With this we have come to the end of this tutorial, let’s summarize.
+
 
+
 
|-
 
|-
 
|| Slide: Summary  
 
|| Slide: Summary  
 
|| In this tutorial, we have learnt
 
|| In this tutorial, we have learnt
 
 
 
* How to install '''Rust'''
 
* How to install '''Rust'''
 
* Some basic '''Rust''' commands  
 
* Some basic '''Rust''' commands  
 
* How to overcome common errors during '''installation'''
 
* How to overcome common errors during '''installation'''
 
* Create and execute '''Rust file'''
 
* Create and execute '''Rust file'''
 
 
 
 
|-
 
|-
 
|| Slide: Assignment
 
|| Slide: Assignment
 
|| As an assignment,
 
|| As an assignment,
 
 
* Create a file '''assignment.rs'''
 
* Create a file '''assignment.rs'''
 
* Print - ‘'''Welcome to Spoken Tutorials!'''’
 
* Print - ‘'''Welcome to Spoken Tutorials!'''’
 
* '''Compile '''and '''execute '''the file.
 
* '''Compile '''and '''execute '''the file.
 
* Observe the output in the '''Terminal'''
 
* Observe the output in the '''Terminal'''
 
 
 
 
|-
 
|-
 
|| '''Slide: '''About Spoken Tutorial Project
 
|| '''Slide: '''About Spoken Tutorial Project
Line 456: Line 340:
 
* The video at the following link summarises the Spoken Tutorial project.
 
* The video at the following link summarises the Spoken Tutorial project.
 
* Please download and watch it
 
* Please download and watch it
 
 
 
 
|-
 
|-
 
|| '''Slide:''' Spoken tutorial workshops
 
|| '''Slide:''' Spoken tutorial workshops
Line 464: Line 345:
 
* We conduct workshops using spoken tutorials and give certificates.
 
* We conduct workshops using spoken tutorials and give certificates.
 
* For more details, please write to us.
 
* For more details, please write to us.
 
 
 
 
|-
 
|-
 
|| '''Slide:'''Answers for THIS Spoken Tutorial
 
|| '''Slide:'''Answers for THIS Spoken Tutorial
Line 476: Line 354:
 
* The Spoken Tutorial project team will ensure an answer
 
* The Spoken Tutorial project team will ensure an answer
 
* You will have to register on this website to ask questions.
 
* You will have to register on this website to ask questions.
 
 
 
 
|-
 
|-
 
|| '''Slide: '''Forum for specific Questions
 
|| '''Slide: '''Forum for specific Questions
Line 486: Line 361:
 
* This will help reduce the clutter.
 
* This will help reduce the clutter.
 
* With less clutter, we can use these discussions as instructional material.
 
* With less clutter, we can use these discussions as instructional material.
 
 
 
 
|-
 
|-
 
|| Slide: Acknowledgement
 
|| Slide: Acknowledgement
 
|| Spoken Tutorial Project is funded by Ministry of Education, Government of India
 
|| Spoken Tutorial Project is funded by Ministry of Education, Government of India
 
 
|-
 
|-
 
|| Slide: Thanks
 
|| Slide: Thanks
 
|| This is Jayesh signing off. Thank you for joining
 
|| This is Jayesh signing off. Thank you for joining
 
 
|}
 
|}

Latest revision as of 11:17, 21 June 2021

Title of the script: Installation of Rust on Linux OS

Author: Jayesh Katta Ramalingaiah

Domain Reviewer: Vigneshwer Dhinakaran

Novice Reviewer: Praveen S

Keywords: Rust, version, rustc, cargo, rustup


Visual Cue
Narration
Slide: Title Welcome to the spoken tutorial on Installation of Rust on Linux OS.
Slide:

Learning Objectives

In this tutorial, we will learn:
  • How to install Rust.
  • Create and execute a Rust file
Slide: System Specifications This tutorial is recorded using:
  • Ubuntu Linux OS version 18.04
  • Rust version 1.47.0
  • Visual Studio Code version 1.45.0 (code editor)

However you may use any other editor of your choice.

Slide: Pre-requisites To practice this tutorial,
  • You need an internet connection to install the necessary packages and
  • You should be familiar with basic Linux commands.
  • If not, please go through the prerequisite Linux tutorials on this website.
Slide: Code files
  • The files used in this tutorial are available in the Code files link on this tutorial page.
  • Pls download and extract the files.
  • Make a copy and then use them for practising.
Only narration Let us begin with the installation of Rust.
Show commands.txt in text editor I have opened the Commands.txt file in a text editor on my machine.

And I will use the same file to copy-paste the commands during the demonstration.

Shortcut to paste commands on the terminal is Shift, Ctrl and V keys.

Narration only Let us begin.
Press Ctrl+Alt+T keys Open the terminal by pressing Ctrl,Alt and T keys simultaneously on the keyboard.

Ensure that you have root permissions to run the commands.

Only Narration Here onwards, please remember to press the Enter key after typing each command.
[Terminal]

Type:

sudo apt-get install curl -y

[Enter]

We will be installing Rust with the help of the curl command line tool.

So, we have to first install curl if we haven’t done so earlier.

To do so type the command as shown on the terminal.

[Terminal]

Enter admin password

If prompted, enter the admin password to proceed further.
[Terminal] Type:

curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

[Enter]

We have successfully installed curl.

Next let us download and install Rust using Curl.

To do so type the command as shown on the terminal.

Only Narration The download may take some time depending upon your internet speed.
[Terminal] Highlight one by one:

Proceed with installation (default)

Customize installation

Cancel installation

Once the package is downloaded, we will be prompted to choose one of the following options:

Proceed with installation (default)

Customize installation

Cancel installation

[Terminal] Type: 1 [Enter] To proceed with default installation, type 1 and press Enter.
[Terminal] Highlight:

Rust is installed now. Great!

We have successfully installed Rust.
[Terminal] Type:

sudo reboot [Enter]

Once the installation is done, we need to restart our computer.

To do so, type sudo reboot in the terminal.

This will restart your computer.

Press Ctrl+Alt+T keys Once you have restarted the computer, open the terminal again.
[Terminal] Type:

rustc --version [Enter]

Now let us cross verify the Rust installation.

Type the command as shown in the terminal.

[Terminal] Highlight:

rustc 1.47.0

This command shows the version of Rust installed in your computer.

The version number may be different in your case.

[Terminal] Type:

rustup [Enter]

Now type rustup on the terminal.
Only narration This shows us a list of commands to run.

rustup is responsible for the complete Rust installation using the curl command.

Slide: Rust Update

rustup update [Enter]

If you wish to update your Rust version, then execute this command on the terminal.
Slide: rustup toolchain list rustup toolchain command lists the various toolchains of Rust installed in your machine.

For now, I have only one stable version installed.

If you have any other versions, then that version would be displayed.

Slide: cargo cargo is a package manager to maintain a Rust project with dependencies.
[Terminal] Type:

cargo [Enter]

You can check whether cargo is installed or not using the cargo command in the terminal.

This shows a list of commands which can be executed using cargo.

[Terminal] Type:

cargo --version [Enter]

This command shows the version of the cargo package manager installed in your machine.
Slide: Common Errors After Installation Common Errors After Installation
  • System restart is required after installing rust.
  • If not, we could land with these errors
    • Rustup
    • Rustc
    • Cargo - command not found
Only narration Next let us learn how to create and execute a Rust file.
Open Visual Studio Code editor. You may use any editor of your choice.

I will use Visual Studio Code editor for this demonstration.

[Editor] Type:

fn main() {

println!("Hello World");

}

In the code editor, type the code as shown.
[Editor] Highlight:

fn main(){

}

This is our main function.
[Editor] Highlight: fn The keyword fn is used as a syntax to create a function in Rust.
[Editor] Highlight: main() main indicated the name of the function.

The Rust execution starts from the main function.

[Editor] Highlight:

{

}

The code written in between the open and closed curly braces would be the function body.
[Editor] Highlight print! Print!() is the print function in Rust.
[Editor] Highlight

Hello World

Here we have Hello World in double quotes as a parameter in the function call.
[Editor] Highlight

print!(“Hello World”)

So, when we run the program, Hello World gets printed.
Press Ctrl + S Let us save the file by pressing Ctrl + S keys together.
Point to Save As dialog box Save dialog box opens.
Select Desktop on the left side Select Desktop location.
Point to Name >> type "hello-world.rs" In the Name field, type the name of the file as hello-world.rs
Highlight .rs The extension .rs states that this is a Rust code file.
Under Desktop >> Create MyRustProject folder And then create a folder named MyRustProject.
Point to MyRustProject From now on, I will be saving my Rust files in this folder.
Click on Save button. Then click on the Save button on the top right corner of the dialog box.
We have created a Rust file and have written the Hello World program.

Now, it’s time to compile and run the file.

Switch to terminal Switch back to the terminal.
[Terminal] Type:

cd Desktop/MyRustProject

[Enter]

Using cd command go to the location where the Rust file is saved.

In my case, it is MyRustProject on the Desktop.

[Terminal] Type:

rustc hello-world.rs [Enter]

To compile, type rustc space filename with extension .rs

In my case it is hello-world.rs

[Terminal] Type:

./hello-world [Enter]

The compilation is done without any error.

Now, to run type the dot slash filename and press Enter.

In my case it is ./hello-world

[Terminal] Highlight:

Hello World

Hello world text gets printed.
Slide: Common Errors

sudo apt install build-essential

  • You could land up with this error while compiling - linker ‘cc’ not found.
  • It means you don’t have gcc in your machine.
  • To resolve this, install the build essentials with this command.
Only narration We have successfully installed Rust and executed the Hello World program.

With this we have come to the end of this tutorial.

Let’s summarize.

Slide: Summary In this tutorial, we have learnt
  • How to install Rust
  • Some basic Rust commands
  • How to overcome common errors during installation
  • Create and execute Rust file
Slide: Assignment As an assignment,
  • Create a file assignment.rs
  • Print - ‘Welcome to Spoken Tutorials!
  • Compile and execute the file.
  • Observe the output in the Terminal
Slide: About Spoken Tutorial Project
  • The video at the following link summarises the Spoken Tutorial project.
  • Please download and watch it
Slide: Spoken tutorial workshops
  • We conduct workshops using spoken tutorials and give certificates.
  • For more details, please write to us.
Slide:Answers for THIS Spoken Tutorial
  • Do you have questions in THIS Spoken Tutorial?
  • Please visit this site
  • Choose the minute and second where you have the question
  • Explain your question briefly
  • The Spoken Tutorial project team will ensure an answer
  • You will have to register on this website to ask questions.
Slide: Forum for specific Questions
  • The Spoken Tutorial forum is for specific questions on this tutorial.
  • Please do not post unrelated and general questions on them.
  • This will help reduce the clutter.
  • With less clutter, we can use these discussions as instructional material.
Slide: Acknowledgement Spoken Tutorial Project is funded by Ministry of Education, Government of India
Slide: Thanks This is Jayesh signing off. Thank you for joining

Contributors and Content Editors

Kr.jayesh, Nancyvarkey, Pravin1389