<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cecília Coelho </title>
    <description>The latest articles on DEV Community by Cecília Coelho  (@ceciliacoelho).</description>
    <link>https://dev.to/ceciliacoelho</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F583279%2F07574d61-2088-4658-a1ba-9acece068e14.png</url>
      <title>DEV Community: Cecília Coelho </title>
      <link>https://dev.to/ceciliacoelho</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ceciliacoelho"/>
    <language>en</language>
    <item>
      <title>How to code a price tracker using Python  - clearly explained (beginner's friendly)
</title>
      <dc:creator>Cecília Coelho </dc:creator>
      <pubDate>Thu, 02 Dec 2021 12:05:30 +0000</pubDate>
      <link>https://dev.to/ceciliacoelho/how-to-code-a-price-tracker-using-python-clearly-explained-beginners-friendly-295f</link>
      <guid>https://dev.to/ceciliacoelho/how-to-code-a-price-tracker-using-python-clearly-explained-beginners-friendly-295f</guid>
      <description>&lt;p&gt;In this beginner's friendly tutorial we will be coding a simple Python script to track the prices of your most wanted products 🤑 (this way you'll never miss those sweet deals 😉) in 5 simple steps: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1-creating a CSV file to store your wishlist and each item's target prices;&lt;/li&gt;
&lt;li&gt;2-getting the price of an item using an URL; &lt;/li&gt;
&lt;li&gt;3-checking if the price is below a target value; &lt;/li&gt;
&lt;li&gt;4-checking all items of a wishlist;&lt;/li&gt;
&lt;li&gt;5-automatic script running (Windows and Linux).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the end you'll have a script that builds a wishlist in a file by adding new items and checks the price of all items in it, warning you if it's the perfect time to spend your money (no more infinite tabs to check every once in a while). &lt;br&gt;
You'll feel like a hacker after this! 🕵️ 👩‍💻&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's go!
&lt;/h3&gt;



&lt;h3&gt;
  
  
  Python libraries we need:
&lt;/h3&gt;

&lt;p&gt;For this project you'll need some Python libraries 🐍, I'll go through them briefly so you get a general idea about them (more exploration is encouraged 🔍). &lt;br&gt;
Make sure you have these installed, if not you can pay a visit to our best friend "The" shell (or terminal).&lt;/p&gt;

&lt;p&gt;-&lt;strong&gt;requests&lt;/strong&gt;: allows you to make HTTP requests, meaning getting the content of a webpage;&lt;/p&gt;

&lt;p&gt;-&lt;strong&gt;BeautifulSoup4&lt;/strong&gt;: parses the content extracted from a webpage;&lt;/p&gt;

&lt;p&gt;-&lt;strong&gt;csv&lt;/strong&gt;: library to read and write CSV (Comma-Separated Values) format files;&lt;/p&gt;

&lt;p&gt;-&lt;strong&gt;re&lt;/strong&gt;: package to use regular expression matching operations. Very powerful to filter strings by matching a specific pattern;&lt;/p&gt;

&lt;p&gt;-&lt;strong&gt;os&lt;/strong&gt;: provides ways to interact with your operating system (removing files, changing current directory, etc.).&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Creating a CSV wishlist
&lt;/h3&gt;

&lt;p&gt;First we need to store our wanted items in a wishlist. This way our script will be able to check the prices of every item without us moving a finger (laziness intensifies 😏). &lt;br&gt;
But what information should the wishlist hold? &lt;br&gt;
Short answer, whatever you want and/or need. In this tutorial we'll be using 3 features to describe each item: the name of the item as in the web page; its web address; and the maximum price we are willing to pay for it (let's call it target price).&lt;br&gt;
To avoid creating a CSV file by hand with our wishlist with the following information,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

item's name , in store url , target price


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;we can make the script create and add new items to the list for us. &lt;br&gt;
So, what's the strategy? 🤔&lt;br&gt;
We are going to start implementing our price tracker function. To make it create and modify the wishlist for us we need to give it some information as input: the path where we want to store the wishlist; the url of the item we want to add; the maximum price we want to pay for that item.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import requests 
import bs4 
import csv 
import re 
from os.path import exists
def tracker(filepath , item='' , target=0):


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Wait a second... 😑&lt;br&gt;
Did we just forget to define the item's name as an input? Well, if you want you can add it but with the URL we can retrieve that information easily.&lt;/p&gt;

&lt;p&gt;Our function is named &lt;em&gt;tracker&lt;/em&gt; and receives a mandatory argument, the path to store the CSV (&lt;em&gt;filepath&lt;/em&gt;), and 2 optional arguments, the item to be added and the target price. &lt;br&gt;
The first optional input argument of our function, &lt;em&gt;item&lt;/em&gt;, receives a string which corresponds to the url of the item we want to add to our wishlist. To add the item, first we need to check if there is a wishlist in the path given by the user or a new one will be created:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    if len(item) != 0:

        if not exists(filepath):
            f = open(filepath , 'w' , encoding='UTF8')
        else:
            f = open(filepath , 'a')

        writer = csv.writer(f)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Remember that we want to have 3 features for each item. The function took as input 2 of them, the URL and the target price (0 if not specified by the user). We are missing the item's name... The process of getting it from the URL is the same as retrieving it's current price so let's get to the powerful part of the tutorial! 🐱‍🏍&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Getting information of an item using an URL
&lt;/h3&gt;

&lt;p&gt;Who has ever randomly pressed a keyboard key while browsing and something really weird (and scary 😬) came up on the side of the webpage? 🙋‍♀️&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1e8h38spd8yvtpzd7wkg.png" alt="Figure"&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Figure 1.&lt;/strong&gt;  Weird scary stuff that pops up on the browser.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The F12 key opens the browser's Developer Tools and, to make it simple, it allows everyone to see the code that is behind a webpage. This includes every piece of text that is being displayed (which is what we are looking for). So, what we want is Python to have access to the code shown in the Developer Tools and get the information we want.&lt;br&gt;
First, we need Python to mimic us when we open an URL and copy the code behind it. This can be done with the requests library:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

rq = requests.get(item , headers=({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', 'Accept-Language': 'en-US, en;q=0.5'}))


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;where &lt;em&gt;item&lt;/em&gt; is the url. You don't need to worry much about the &lt;em&gt;headers&lt;/em&gt; argument of the &lt;em&gt;get()&lt;/em&gt; but if you are curious on why we are passing that information read the note below, else just skip it. ⏩&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;NOTE:&lt;/em&gt;&lt;/strong&gt;  When we use a browser to access a webpage, the servers hosting the page know which browser the user is using so it can send the page optimized to that specific browser. If this information is not available then we may run into some problems: the code gotten from the request is not the same as the one we see in our browser; the server can block unrecognized traffic so it prevents Python to get the info. In this tutorial we are pretending to be using Mozilla Firefox 😉. In addition to this, we want to get the webpage in English despite of our system's preferences.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This code line outputs a &lt;em&gt;Response&lt;/em&gt; object, to easily access the information it contains we use &lt;em&gt;BeautifulSoup&lt;/em&gt; so everything stays nice and pretty in a nested structure which makes it a breeze to navigate. 🧭&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 info = bs4.BeautifulSoup(rq.content , features='lxml') 


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and if we print the variable (or store in a file) we will get something like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj40wjlj8thzmic7z2w1f.png" alt="Figure"&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Figure 2.&lt;/strong&gt;  Retrieved information in a nested structure.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now that we have all the code behind the webpage let's extract what we want. First we are going to find out how to retrieve the item's name, to do this you need to find the id tag that holds that piece of information. &lt;br&gt;
Open the url on your browser and press F12 to unveil the secrets of the universe! (not really... but it's something 😅). &lt;br&gt;
Use the find command (ctrl+f) to search for the item's name, the one you can see in the webpage, and check the id, that's what we are going to use.&lt;br&gt;
Remember the code we extracted from the webpage right before this? With the id that holds the item's name we can search the retrieved information using the following line of code (the &lt;em&gt;strip()&lt;/em&gt; makes sure to remove all extra spaces):  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

name = info.find(id = "productTitle").get_text().strip()


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Similarly, to get the item's price you just have to follow the same steps.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

price = info.find(id = "price_inside_buybox").get_text().strip()


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you print the &lt;em&gt;price&lt;/em&gt; variable you'll notice that it comes not only with numeric info but also the currency identifier (example: 'USD9.99'). This makes it impossible to compare it with a target price or do any kind of statistical approach, boring...🥱.&lt;br&gt;
Let's get rid of it! To do that, we can split the &lt;em&gt;price&lt;/em&gt; variable by a regular expression and keep the last bit ('9.99'). The goal is to split the string on the first number that appears. Adding this to the code line above comes:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

price = re.split(r'(^[^\d]+)', info.find(id = "price_inside_buybox").get_text().strip())[-1]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we have all information needed to add the item into the CSV wishlist so let's do it. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

writer.writerow([name , item , target , price])


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In addition to the features of the item (name, url, target price), we'll also write the price we just retrieved. This way you can keep the price history (this can be used for lot's of cool stuff like a Machine Learning model to predict future price drops 🤩). &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Checking if it's time to buy
&lt;/h3&gt;

&lt;p&gt;We added the item to our wishlist, now it's time for difficult decisions. Are we ready to drop the money? 🙄&lt;br&gt;
If we declared the maximum amount of money we want to spend then, the &lt;em&gt;target&lt;/em&gt; input variable will hold it and store a value different from 0 or negative (sorry to ruin the party but no one is going to pay you to get something 🤯 or is it... 😶) . Our Python script should let us know when the current price is under our buying limit.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

if target &amp;gt; 0 and price &amp;lt;= target: 
    print("BUY IT NOW!!!!!!!!!!!!!!!!!!!")


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 4: Checking all items of a wishlist
&lt;/h3&gt;

&lt;p&gt;We are almost done, hang in there! 💪&lt;br&gt;
Imagine we added 5 items into our wishlist and we want to check if any gets in our price range. To do this we have to: open the CSV file; extract every item's URL and target price; use the same code of Step 2 and Step 3; (bonus) store the current price on the CSV file.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

        fread = open(filepath , 'r')
        items = list(csv.reader(fread))
        fread.close()

        fwrite = open(filepath , 'w')
        wr = csv.writer(fwrite)

        for i in range(len(items)):

            rq = requests.get(items[i][1] , headers=({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', 'Accept-Language': 'en-US, en;q=0.5'}))
            info = bs4.BeautifulSoup(rq.content , features='lxml') 

            price = re.split(r'(^[^\d]+)', info.find(id = "price_inside_buybox").get_text().strip())[-1]
                items[i].append(price)

            if items[i][2] &amp;gt; 0 and price &amp;lt;= items[i][2]:
                print("BUY IT NOW!!!!!!!!!!!!!!!!!!!")


        wr.writerows(items)
        fwrite.close()


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠ &lt;strong&gt;&lt;em&gt;WARNING&lt;/em&gt;&lt;/strong&gt;   ⚠&lt;br&gt;
If you run this script a considerable amount of times you can get an error stating that the id couldn't be found don't worry, this happens because the server hosting an URL has blocked you 🙁 . Each time you run this script a request is sent from your IP address to the target server, if the server gets several requests from you in a very short period of time it will classify your traffic as not normal and block your access. In this case just wait till the next day 😉. &lt;br&gt;
To prevent the script from crashing if a URL is blocked, and still check the others, we can add some try and except blocks. Check the full code below.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import requests
import bs4
import csv
import re
from os.path import exists

def tracker(filepath , item='' , target=0):

    if len(item) != 0:

        if not exists(filepath):
            f = open(filepath , 'w' , encoding='UTF8')
        else:
            f = open(filepath , 'a')

        writer = csv.writer(f)
        rq = requests.get(item , headers=({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', 'Accept-Language': 'en-US, en;q=0.5'}))
        info = bs4.BeautifulSoup(rq.content , features='lxml') 

        try:
            name = info.find(id = "productTitle").get_text().strip()
            price = re.split(r'(^[^\d]+)', info.find(id = "price_inside_buybox").get_text().strip())[-1]

            if target &amp;gt; 0 and price &amp;lt;= target:
                print("BUY IT NOW!!!!!!!!!!!!!!!!!!!")

            writer.writerow([name , item , target , price])

        except:
            raise Exception("Couldn't retrieve product's info")

    else:
        fread = open(filepath , 'r')
        items = list(csv.reader(fread))
        fread.close()

        fwrite = open(filepath , 'w')
        wr = csv.writer(fwrite)

        for i in range(len(items)):

            rq = requests.get(items[i][1] , headers=({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', 'Accept-Language': 'en-US, en;q=0.5'}))
            info = bs4.BeautifulSoup(rq.content , features='lxml') 

            try:
                price = re.split(r'(^[^\d]+)', info.find(id = "price_inside_buybox").get_text().strip())[-1]
                items[i].append(price)

                if items[i][2] &amp;gt; 0 and price &amp;lt;= items[i][2]:
                    print("BUY IT NOW!!!!!!!!!!!!!!!!!!!" + items[i][1])

            except:
                raise Exception("Couldn't retrieve product's info")

        wr.writerows(items)
        fwrite.close()

tracker("items.csv")



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 5: Automatic script running
&lt;/h3&gt;

&lt;p&gt;To have our script running everyday, without us worrying about it, we can schedule it to run at specific times.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Windows users&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;First you need to create an executable which will run the script. To do that create a text file and change it's extention to &lt;em&gt;.bat&lt;/em&gt; ;&lt;/li&gt;
&lt;li&gt;Inside the file, add the path to the Python executable in your computer and the path to the script in the following format:
```
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt; &lt;br&gt;
pause&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The *pause* prevents the terminal from closing after completion, you can remove it if you want. If you click the *.bat* file it will now run the script! To automatize the clicking action we will use the Windows Task Scheduler.

- Use the searcher to find Task Scheduler and click "Create Basic Task" ;
- Choose the task's name, occurrence frequency and trigger time;
- Give the path to the *.bat* file we just created;
- Finish!

|![Figure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7jjnctm8gf069ljzdhzo.png)|
|:--:| 
| **Figure 3.**  Steps to schedule a task on Windows.|


#### 🐧 **Linux users**

First we you need to make sure you have *cron* installed and enable to start on boot. If not, for fedora, do: 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;dnf install cronie cronie-anacron&lt;br&gt;
systemctl enable crond&lt;br&gt;
chkconfig crond on&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Now we need to schedule the task using *cron*.

- Go to the terminal and do ```crontab

 -e

``` to open the file where all scheduled tasks are, if any;
- Add a line with the following ```0

 10 * * * python/path price/tracker/path

```. This means the script will run every day at 10a.m. To mess with the scheduling time you can use https://crontab.guru/ ;
- Save and exit. You should see this output on the terminal ```crontab:

 installing new crontab

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Finish!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;All set! Goodbye missed deals!&lt;/strong&gt; 👏😁&lt;/p&gt;

&lt;p&gt;❗&lt;strong&gt;BONUS TIP&lt;/strong&gt; ❗&lt;br&gt;
With this script you can do awesome things, just let your imagination run wild! I'll list some below, have fun! 🤗&lt;/p&gt;

&lt;p&gt;-price predicter;&lt;br&gt;
-price variation analysis;&lt;br&gt;
-restock alerts;&lt;br&gt;
-price comparison between several stores.&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>beginners</category>
      <category>webscrapping</category>
    </item>
    <item>
      <title>How to host a worldwide private Git server 🌍 on a Raspberry Pi - clearly explained (beginner's friendly)</title>
      <dc:creator>Cecília Coelho </dc:creator>
      <pubDate>Mon, 30 Aug 2021 14:14:56 +0000</pubDate>
      <link>https://dev.to/ceciliacoelho/how-to-host-a-worldwide-private-git-server-on-a-raspberry-pi-clearly-explained-beginner-s-friendly-2pf5</link>
      <guid>https://dev.to/ceciliacoelho/how-to-host-a-worldwide-private-git-server-on-a-raspberry-pi-clearly-explained-beginner-s-friendly-2pf5</guid>
      <description>&lt;p&gt;In this beginner's friendly tutorial we will be setting up a Raspberry Pi (aka Pi) to host your very own private Git server that will be staying in the comfort of your home 🏡. This way you can have your (&lt;em&gt;very important highly secret&lt;/em&gt; 😈) projects backed-up and accessible without relying on external agents (like GitHub, GitLab, etc) in 5 simple steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  1-Git installation&lt;/li&gt;
&lt;li&gt;  2-Mounting a USB drive&lt;/li&gt;
&lt;li&gt;  3-Initializing a Git repository&lt;/li&gt;
&lt;li&gt;  4-Add/Commit/Push into your Raspberry Pi&lt;/li&gt;
&lt;li&gt;  5-Using your Git server anywhere&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before we start, I'm assuming you already have setup your Pi and have SSH enabled. If you don't follow this guide: &lt;a href="https://dev.to/ceciliacoelho/how-to-setup-a-headless-raspberry-pi-clearly-explained-beginner-s-friendly-4aph"&gt;https://dev.to/ceciliacoelho/how-to-setup-a-headless-raspberry-pi-clearly-explained-beginner-s-friendly-4aph&lt;/a&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  📝 What we will be using:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Laptop&lt;/li&gt;
&lt;li&gt;  Raspberry Pi 4&lt;/li&gt;
&lt;li&gt;  USB (any size you need)&lt;/li&gt;
&lt;li&gt;  Internet Router&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1: Git installation
&lt;/h3&gt;

&lt;p&gt;SSH into your Raspberry Pi using your laptop (or use VNC Viewer and open the terminal in the desktop). First we are going to make sure everything is up-to-date,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt-get update&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo apt-get upgrade&lt;/code&gt;&lt;br&gt;
and reboot &lt;code&gt;sudo reboot&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Again, access your Pi to install Git,&lt;br&gt;
&lt;code&gt;sudo apt-get install wget git&lt;/code&gt;&lt;br&gt;
When it's finished turn off the Pi.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Mounting a USB drive
&lt;/h3&gt;

&lt;p&gt;Plug your USB drive into the Raspberry Pi (make sure it's formatted as FAT) and turn the Pi back on and SSH into it.&lt;br&gt;
Now we are going to create and assign a directory to this USB so every time we want to access our projects we know exactly where they are 📌. To create the directory do&lt;br&gt;
&lt;code&gt;mkdir usbdrv&lt;/code&gt; &lt;br&gt;
and now we need to map the USB to it. To do that first let's get the USB info, do&lt;br&gt;
&lt;code&gt;sudo blkid&lt;/code&gt;&lt;br&gt;
you should get something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="5DE4-665C" TYPE="vfat" PARTUUID="225e7479-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="7295bbc3-bbc2-4267-9fa0-099e10ef5bf0" TYPE="ext4" PARTUUID="225e7479-02"
/dev/mmcblk0: PTUUID="225e7479" PTTYPE="dos"
/dev/sda1: LABEL="GITPI" UUID="F234-F2DF" TYPE="vfat" PARTUUID="0f6f2c0f-01"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When I formatted my USB I gave it the label "GITPI" so the last line of the above block corresponds to the information I'm looking for, you should have something similar for yours.&lt;br&gt;
Let's tell the Pi that our USB contents should go to the created "usbdrv" directory by editing the "systems table" file, do&lt;br&gt;
&lt;code&gt;sudo nano /etc/fstab&lt;/code&gt;&lt;br&gt;
A file should have popped up in a text editor, in the end of the file add this line (my USB was at /dev/sda1 as you can see in the output of &lt;code&gt;sudo blkid&lt;/code&gt;, make sure to replace by whatever you got):&lt;br&gt;
&lt;code&gt;/dev/sda1 /home/pi/usbdrv vfat uid=pi,gid=pi,umask=0022,sync,auto,nosuid,rw,nouser 0 0&lt;/code&gt;&lt;br&gt;
to save and close the file &lt;strong&gt;Ctrl-x -&amp;gt; Y -&amp;gt; return&lt;/strong&gt;.&lt;br&gt;
Once more, it's reboot time! 😅&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3: Initializing a Git repository
&lt;/h3&gt;

&lt;p&gt;Now go to your laptop where you "work" **cough cough** 🙄, you can create a blank folder to start a new project or you already have one full of juice 😉, the step is the same. Initialize a Git repository in the folder using &lt;code&gt;git init&lt;/code&gt;.&lt;br&gt;
Back to the Pi 🥧,  create a folder with the &lt;em&gt;.git&lt;/em&gt; extension to hold the repository, do (replace &lt;em&gt;projectname&lt;/em&gt; by the name you want to give your repository)&lt;br&gt;
&lt;code&gt;mkdir usbdrv/projectname.git&lt;/code&gt;&lt;br&gt;
Go into the directory you just created&lt;br&gt;
&lt;code&gt;cd usbdrv/projectname.git&lt;/code&gt; &lt;br&gt;
and create an empty repository,&lt;br&gt;
&lt;code&gt;git init --bare&lt;/code&gt;&lt;br&gt;
you should get this output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Initialized empty Git repository in /home/pi/usbdrv/projectname.git/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❗❗ If you get permission denied while executing these commands try and add &lt;code&gt;sudo&lt;/code&gt; to the beginning of each.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Add/Commit/Push into your Raspberry Pi
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Finally the magic is going to happen!!!!! 🧙‍♂️
&lt;/h4&gt;

&lt;p&gt;Go to your laptop and create a file if the folder is empty, otherwise we already have stuff to push into our private Git, how exciting! 😁&lt;br&gt;
First we need to add the remote, do&lt;br&gt;
&lt;code&gt;$ git remote add pi pi@192.168.50.166:/home/pi/usbdrv/projectname.git&lt;/code&gt;&lt;br&gt;
where the first "pi" will be the name we'll be using when pushing. Don't forget to plug in your Raspberry Pi address (the same you use to ssh) and the name of your git folder (created in step 3).&lt;/p&gt;

&lt;h4&gt;
  
  
  Now, for the main event, the Add/Commit/Push triathlon! 🏊‍🚴‍♂️🏃‍♂️💨
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git commit -m "first commit: is this really working?"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git push pi master&lt;/code&gt;
It is going to ask for your Raspberry Pi password for the user you are currently using, I'm using &lt;em&gt;pi&lt;/em&gt;.
If everything went well you should get this output:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 222 bytes | 222.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To 192.168.50.166:/home/pi/usbdrv/projectname.git
 * [new branch]      master -&amp;gt; master

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks like a success right? 🤔&lt;br&gt;
If you are like me and you want to be sure your stuff is really on that USB and make sure if something happens with your Pi you can just plug the USB on any laptop and you'll have access to everything then stay with me!🧐&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Turn off the Raspberry Pi and unplug the USB;&lt;/li&gt;
&lt;li&gt;Plug the USB into your laptop;&lt;/li&gt;
&lt;li&gt;Go to the USB and open everything your eyes see; 😦&lt;/li&gt;
&lt;li&gt;Fail to find anything that looks like what you just push; 😨&lt;/li&gt;
&lt;li&gt;Panic! 😱😱😱😱😱&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Wait a second!
&lt;/h4&gt;

&lt;p&gt;The USB has a Git repository so you won't be able to see your files like that 😏. &lt;br&gt;
Use the terminal to navigate to somewhere you want to put your stuff in and do,&lt;br&gt;
&lt;code&gt;git clone pathToUSB/projectname.git&lt;/code&gt;&lt;br&gt;
This command will clone your repository and when it's over you should see what you were expecting, your files! 🤗&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Using your Git server anywhere 🌍
&lt;/h3&gt;

&lt;p&gt;The steps explained above will only work in case the laptop you are using to access the Git server is on the same network of the Raspberry Pi hosting it, meaning both have to be connected to the same router (via Wi-Fi or LAN).&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;HOW LAME!&lt;/strong&gt;  😒&lt;/p&gt;



&lt;p&gt;What we want is a Git server that we can use anywhere, outside and inside the Raspberry's network. To do this we need what is called port forwarding and the steps to setting it up will depend on the router you have. Note that port forwarding is considered dangerous since it gives access to your local network from the outside, make sure you use strong passwords at least. &lt;br&gt;
The steps to perform the above instructions on your router can be found in the user manual or online:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Assign a static IP address for the Raspberry Pi:&lt;/strong&gt; this will prevent us from losing the address of the Pi due to router reassignment. To do this you need to access your router's through a web browser by using its IP address and navigate to the page where you can manually assign IP, Figure 1.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87xpuhzok1dpl1snuzeg.png" alt="Figure"&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Figure 1.&lt;/strong&gt;  Page to assign a static IP address.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;After adding the Raspberry Pi, reboot.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Port forwarding:&lt;/strong&gt; launch the router's configuration web page again and look for the port forwarding page, Figure 2.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtrnln5mjca0au59clrk.png" alt="Figure"&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Figure 2.&lt;/strong&gt;  Port forwarding page.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Fill in the required information and make sure the &lt;em&gt;Port&lt;/em&gt; is 22, this is the SSH port used by the Raspberry Pi, and use &lt;em&gt;Protocol&lt;/em&gt; TCP.&lt;/p&gt;

&lt;p&gt;Now we will setup the remote of the git repository to be the universal address of the Pi, that you will be able to access from anywhere! Go back to the project you setup in step 4 and do (where "222" is the value you chose for &lt;em&gt;Port Range&lt;/em&gt;):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ git remote add remotepi pi@192.168.40.16:222/home/pi/usbdrv/projectname.git&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Everything is set now, get on the next plane to wherever and let's try! 🛫😎
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git commit -m "commit from the North pole!"&lt;/code&gt; ⛄&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git push remotepi master&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  That's it, first push outside the Raspberry Pi's network!
&lt;/h4&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Success! You are now ready to build some awesome projects!!!&lt;/strong&gt;  🤩💪🎉🎉🎉🎉🎉🎉🎉
&lt;/h3&gt;

&lt;p&gt;If you run into any problems just leave a comment. 😉&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>git</category>
      <category>linux</category>
    </item>
    <item>
      <title>How to setup a headless Raspberry Pi - clearly explained  (beginner's friendly)</title>
      <dc:creator>Cecília Coelho </dc:creator>
      <pubDate>Fri, 20 Aug 2021 18:34:05 +0000</pubDate>
      <link>https://dev.to/ceciliacoelho/how-to-setup-a-headless-raspberry-pi-clearly-explained-beginner-s-friendly-4aph</link>
      <guid>https://dev.to/ceciliacoelho/how-to-setup-a-headless-raspberry-pi-clearly-explained-beginner-s-friendly-4aph</guid>
      <description>&lt;p&gt;In this beginner's friendly tutorial we will be setting up a Raspberry Pi (aka Pi) without an external monitor and keyboard (some of us just have a laptop 🤷‍♀️) in 4 simple steps: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1-getting an OS into the microSD card; &lt;/li&gt;
&lt;li&gt;2-allowing remote access in a local network; &lt;/li&gt;
&lt;li&gt;3-discovering the address and connecting in terminal; &lt;/li&gt;
&lt;li&gt;4-viewing the desktop.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, a small discussion on how to choose an Operating System (OS) for a headless setup is also given, so you can later play around if you wish too 😉. &lt;/p&gt;


&lt;h3&gt;
  
  
  📝 What we will be using:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Laptop&lt;/li&gt;
&lt;li&gt;Raspberry Pi 4 &lt;/li&gt;
&lt;li&gt;MicroSD card (whatever size you want, bigger is better)&lt;/li&gt;
&lt;li&gt;Power supply&lt;/li&gt;
&lt;li&gt;Ethernet cable (optional but recommended)&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Step 1: Getting an OS in the microSD card
&lt;/h3&gt;

&lt;p&gt;Install an imaging utility that will get an OS into our microSD card. The easiest, and thanks to the Raspberry Pi Foundation team, is to use the official Raspberry Pi Imager (get it here: &lt;a href="https://www.raspberrypi.org/blog/raspberry-pi-imager-imaging-utility/" rel="noopener noreferrer"&gt;https://www.raspberrypi.org/blog/raspberry-pi-imager-imaging-utility/&lt;/a&gt;). &lt;br&gt;
After installing, insert your microSD card into your laptop and open the Raspberry Pi Imager, you will be greeted by the screen in Figure 1 (a). &lt;br&gt;
To see the given OS options click the "choose OS" button (Figure 1 (b)), the most straightforward option is to go with the recommended Raspberry Pi OS (32-bit). That's us! 🙋‍♀️🙋‍♂️&lt;br&gt;
Choose the microSD as storage, click the write button and wait till a pop-up message appears stating to remove the card. &lt;br&gt;
Note that the Imager has a whole lot of options including: two more versions of the Raspberry OS (Figure 1 (c)); other general OS (Figure 1 (d)) and several focused OS that we will skip (for now at least).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fawfs5oex6hit9y585wdl.png" alt="Figure"&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Figure 1.&lt;/strong&gt;  Raspberry Pi Imager interface: (a) main window; (b) choose OS options; (c) Raspberry Pi OS options; (d) other general OS options.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If you are feeling adventurous you can go ahead and pick other OS, the steps will be identical, you just need to pay attention to some details:&lt;/p&gt;

&lt;p&gt;❗ &lt;strong&gt;You can jump to step 2 if you don't want details about OS choices&lt;/strong&gt; ❗&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Headless friendly&lt;/strong&gt; - Since we are doing a headless setup (no monitor), we need to make sure the OS supports it or you won't be able to access your Pi, in the first boot up, using your laptop. I learned this the hard way after some experimentation (and a lot of headaches) 😓.  The only OS option you need to be careful with is the Manjaro-ARM Linux. If you want to try it make sure to choose the minimal version since all others will require a monitor to do the initial setup. (To check if an OS has headless setup you can check the documentation of the release);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Different distributions&lt;/strong&gt; - All OS available in the Imager are Debian except Manjaro, which is Arch based. The commands used with Debian won't work when using Manjaro;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Storage&lt;/strong&gt; - If you are running low on resources (4GB microSD card) or you are "The Scrooge McDuck" 🤑 of storage, you may have noticed that  there are options that take roughly half the space of others! The Raspberry Pi OS has three versions: Lite, that doesn't include a Graphical User Interface (GUI) so you can only use the terminal (hacker style!); the recommended includes a GUI; Full includes a GUI and some pre-installed software. If you are a beginner and want to try a no-GUI version but are not sure if you will regret it, don't worry, you can always install a GUI using the terminal (coming soon); 😉&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt; - Are you a beginner that wants to discover Linux or have a specific project in mind? If you want to use you Raspberry Pi to host a Git server, a cloud storage or something similar, you won't be needing a GUI, and doing so will just waste resources, so you can choose a version without a desktop environment (like Raspberry Pi OS Lite or Manjaro ARM Minimal).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Step 2: Allowing remote access in a local network
&lt;/h3&gt;

&lt;p&gt;Insert the microSD card into your laptop so we can modify it to tell our Pi we are going to access remotely, using what is called SSH. &lt;br&gt;
Open the file explorer, you will see a bunch of folders and files, create a new file without extension called "ssh", you should see something like Figure 2.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffgoyia830cj92nf5h6gc.png" alt="Figure"&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Figure 2.&lt;/strong&gt;  The created SSH file should look like this.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This file will make the Pi enable SSH when it turns on, and thus making it possible for us to access it using our laptop's terminal when both are on the same network.&lt;br&gt;&lt;br&gt;
To connect the Pi to the same network as your laptop you can use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ethernet cable: Plug the cable onto the Pi and your internet router and you're ready to go!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wifi: Just like the ssh file, create a file named "wpa_supplicant.conf". This will store your wifi's name and password so the Pi will read this file when starting and connect to your wifi. Open the created file and copy/paste the following and substitute the "WIFI_NAME" and "WIFI_PASSWORD" fields with the login details:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

 update_config=1

country=US

network={

    ssid="WIFI_NAME"

    psk="WIFI_PASSWORD"

    scan_ssid=1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Step 3: Discovering the address and connecting in terminal
&lt;/h3&gt;

&lt;p&gt;Remove the microSD card from your laptop, plug it into your Raspberry Pi and connect a power supply. You will see a green light turning on, this means our Pi is now alive! 🤗&lt;br&gt;
Now, go to your laptop and open the terminal (in Windows it's called Command Prompt). &lt;br&gt;
Now we are going to check if the Pi was able to connect to our network, use the command &lt;code&gt;ping raspberrypi&lt;/code&gt; and you should see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pinging raspberrypi.local [192.168.50.166] with 32 bytes of data:
Reply from 192.168.50.166: bytes=32 time&amp;lt;1ms TTL=64
Reply from 192.168.50.166: bytes=32 time&amp;lt;1ms TTL=64
Reply from 192.168.50.166: bytes=32 time&amp;lt;1ms TTL=64
Reply from 192.168.50.166: bytes=32 time&amp;lt;1ms TTL=64

Ping statistics for 192.168.50.166:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is like the Pi shouting "I'm alive!" 🎉 and it tells where its home is in case we want to go over and say hi (don't forget the 🥧), mine lives at 192.168.50.166. &lt;br&gt;
You now know your Pi's address so let's access it using &lt;code&gt;ssh pi@192.168.50.166&lt;/code&gt;.  It will ask you for a password, since it's the first login then it has to be the default one, use &lt;code&gt;raspberry&lt;/code&gt; (the prompt won't move, it's normal). If you were successful the location on your terminal should have changed to &lt;code&gt;pi@raspberrypi:~ $&lt;/code&gt;, this means we are now working in the Raspberry Pi!&lt;/p&gt;

&lt;p&gt;❗ Note that if you choose an OS other than Raspberry Pi OS (also referred as Raspbian), the default user (pi) and password (raspberry) may be different, you know who to ask 🧐. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4:  Viewing the desktop
&lt;/h3&gt;

&lt;p&gt;The terminal is great but we want to see the Graphical User Interface to play around with Linux in a more friendly way. To do this we need a software that allows to control a remote desktop, we are going to use VNC Server. &lt;br&gt;
First let's make sure our Pi has the latest updates, on the terminal do,&lt;br&gt;
&lt;code&gt;pi@raspberrypi:~ $ sudo apt-get update&lt;/code&gt;&lt;br&gt;
&lt;code&gt;pi@raspberrypi:~ $ sudo apt-get upgrade&lt;/code&gt;&lt;br&gt;
and wait (quick, run and grab some coffee 🏃‍♂️☕).&lt;br&gt;
Now we need to install the VNC Server using &lt;code&gt;sudo apt–get install realvnc–vnc–server realvnc–vnc–viewer&lt;/code&gt; (if it gives an error and you copy/paste the command try rewriting the dashes, sometimes it pastes a double dash 🙄).&lt;br&gt;
When the installation finishes we need to enable it, do,&lt;br&gt;
&lt;code&gt;sudo raspi-config&lt;/code&gt;&lt;br&gt;
a pop-up window will appear, Figure 3. Use the arrows and return button to go to "3: Interface Options" -&amp;gt; "P3 VNC" and select "Yes".&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5idpldpi0qjyq24gv9ec.png" alt="Figure"&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Figure 3.&lt;/strong&gt; Configuration options pop-up window.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Almost done! Now we have to install the VNC Viewer in our laptop, I use RealVNC (find it here: &lt;a href="https://www.realvnc.com/en/connect/download/viewer/" rel="noopener noreferrer"&gt;https://www.realvnc.com/en/connect/download/viewer/&lt;/a&gt;).&lt;br&gt;
After installing, launch the software and write your Pi address on the top bar and hit enter, Figure 4. A pop-up window will ask for your credentials to access, after that you will be able to see your Raspberry Pi's desktop! &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa26i17n9t0wu3zs1y61y.png" alt="Figure"&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Figure 4.&lt;/strong&gt; Accessing the Raspberry Pi desktop with VNC Viewer by entering its address. After doing this the first time, an icon will appear to ease future accesses.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;p&gt;❗❗ If all you can see is a black screen go back to the Pi's terminal and do &lt;code&gt;sudo raspi-config&lt;/code&gt;. Navigate to "Display Options" -&amp;gt; "Resolution" and choose an option other than "default". Reboot you Pi &lt;code&gt;sudo reboot&lt;/code&gt; and try accessing again on the VNC Viewer. It should work now!&lt;/p&gt;



&lt;h1&gt;
  
  
  That's it! Now it's play time! 🥳🥳🥳🥳
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Don't worry, if you mess up something you can always redo all this steps and you'll have a fresh OS to destroy again! 😈🔪
&lt;/h2&gt;

</description>
      <category>linux</category>
      <category>raspberrypi</category>
      <category>beginners</category>
      <category>ssh</category>
    </item>
  </channel>
</rss>
