Linux Setup

  • In the 1980s, GNU was developed at MIT. GNU stands for “GNU’s not Unix” and was made as a free, open source set of the existing Unix system tools. And in 1991, Linus Torvalds developed a free, open source version of the Unix kernel called Linux.
  • Linux is widely used today in mobile devices, desktops, supercomputers, data centers, and cloud servers.
  • Linux distributions (also known as distros) differ by their UIs, shell applications, and how the OS is supported and built.
  • The design of a distro is catered toward its specific audience and/or use case. Popular Linux distributions include Red Hat Enterprise Linux (RHEL), Debian, Ubuntu, Suse (SLES, SLED, OpenSuse), Fedora, Mint, and Arch.
  • The Linux system consists of five key layers: the UI, application, OS, kernel, and hardware.
    • The user interface enables users to interact with applications.
    • Applications enable users to perform tasks within the system
    • The operating system runs on top of the kernel and is vital for system health and stability and
    • The kernel is the lowest-level software that enables applications to interact with hardware
    • Hardware includes all the physical or electronic components of your PC.
  • You can use a variety of command-line or GUI-based text editors such as GNU nano, vim, vi, and gedit.
  • .deb and .rpm are distinct file types used by package mangers in Linux operating systems.
  • You can use GUI-based and command-line package managers to update and install software on Linux systems.

Updating


  • sudo : “super-user do” - you’ll need sudo to activate the apt command
  • apt : Advanced Packaging Tool, is used to perform system admin operations such as installing software packages, upgrading existing packages, updating your system…
  • update : before installing or upgrading any packages it is best to first update your package list index
    • apt will access those resources in file /etc/apt/sources.list
sudo apt update

Nano


nano is a simple command line editor that enables you to use the terminal window as a text editor.

The system I happen to be on already had nano installed, so we’ll upgrade it with

sudo apt upgrade nano
# Create and edit a file
nano hello_world.txt

# type some text in the file and exit/save

# view content with
cat hello_world.txt

Vim


Another popular text-editing program is Vim. Vim is a highly configurable text editor built for efficiency. It takes some practice to get good at using Vim, but the time investment is very worthwhile.

Because Vim isn’t preinstalled on your Linux system, you’ll need to install it yourself. If you haven’t already done so in this session, ensure you run the command sudo apt update. Then to install Vim, enter the following command:

sudo apt install vim

Vim has two basic modes: 

  • Insert mode, where you enter text, and
  • Command mode, where you do everything else.
  • You can start Vim simply by entering
vim

  • You get this screen above
  • type :help
  • When done enter :q
# create a file
vim hello_world_2.txt

# type i to INSERT & type in the text you want, when done press Esc to exit the INSERT mode and back to the command mode
i
Type in the text(when done)
<Esc>
# save the work by typing
:w
# vim will return the file name, nunmber of lines and number of characters written in the file

Packages


Packages are archived files containing the required components for either installing new software or updating existing software. Different Linux distros provide different packages managers. Deb and RPM packages are used by package managers in Linux OS

  • .deb files are used for distributions such as: Debian, Ubuntu and Mint
  • .rpm files are used for Red Hat-based distributions such as: CentOS/RHEL, Fedora, OpenSUSE

You can convert one package to another as they both can be used in one another distro. Use the following

# RPM to deb:
alien <package-name>.rpm

# deb to RPM
alien -r <package-name>.deb

Some package managers are:

  • PackageKit
  • Yum
  • pip
  • conda

GitBash


GitBash accommodates Linux commands, and I happen to have it on my system so I’ll briefly go through how to load packages to it

Load packages in GitBash

I’ll use GitBash as the Linux equivalent, as it’s the simplest to setup since it’s already on my computer.

All I had to do was install:

wget

  • Downloaded the .exe file
  • From Windows Search: GitBash
  • File location
  • Properties
  • Copied the path to the ~\Git
  • Go to that location ~\Git\mingw64\bin
  • Paste the wget .exe application file in that folder

cronetab

  • Was not installed so using
  • winget install cron

Install WSL -Ubuntu


I am using a winows laptop so I thought I’d activate WSL which is built-in windows to accommodate Linux. In W Powershell to install WSL, which automatically insall Linux: Ubuntu

wsl - - install
# It installed Ubuntu v2 To check the installation from Powershell
wsl -l -v

Install Linux - Ubuntu

Ubuntu: command prompt

yashaya@YASHAYA:~$

If you forgot the password for your Linux distribution:

  1. Open PowerShell and enter the root of your default WSL distribution using the command: wsl -u root

    If you need to update the forgotten password on a distribution that is not your default, use the command: wsl -d Debian -u root, replacing Debian with the name of your targeted distribution.

  2. Once your WSL distribution has been opened at the root level inside PowerShell, you can use this command to update your password: passwd <username> where <username> is the username of the account in the distribution whose password you’ve forgotten.

  3. You will be prompted to enter a new UNIX password and then confirm that password. Once you’re told that the password has updated successfully, close WSL inside of PowerShell using the command: exit.

Update & Upgrade Ubuntu

sudo apt update && sudo apt upgrade

Share Ubuntu with Windows Powershell

  • Here we are assigning the ubuntu user profile to a variable
  • We are employing environment variable sharing
  • /p translates any paths between Windows and our Linux instance
  • so when we execute ubuntu.exe in powershell it sends us to ubuntu
  • and now if we print the value of the userprofile in ubuntu we get the user profile from windows
PS C:\Users\EMHRC> $env:WSLENV="USERPROFILE/p"
PS C:\Users\EMHRC> ubuntu.exe
yashaya@YASHAYA:~$ echo $USERPROFILE
/mnt/c/Users/EMHRC
yashaya@YASHAYA:~$ ls /mnt/c/Users/EMHRC
# ----  OUTPUT -----
 1_017_SvsP_Region_filter_lambda_span_vbar_legend.ipynb
 AppData
'Application Data'
 Contacts
 Cookies
 Documents
 Downloads
 Favorites ....

So to access Windows files use /mnt/ before the drive letters everything else works as if you have direct access to all the files in all the drives on the laptop/desktop

# -- Change to working directory
yashaya@YASHAYA:~$ cd /mnt/d/data/Linux_projects/Final_projects/C6_M4
$ dir
15-executable.jpg       17-contab.jpg  T10.jpg  T12.jpg  T2.jpg  T4.jpg  T6.jpg  T8.jpg  backup-1727468717.tar.gz  important-documents      rx_poc.log
16-backup-complete.jpg  T1.jpg         T11.jpg  T13.jpg  T3.jpg  T5.jpg  T7.jpg  T9.jpg  backup.sh                 important-documents.zip

Install MySQL


  • To interact with MySQL databases on your local machine, you need to install and start the MySQL server. To install the MySQL server run the following command.
  • This command will prompt you to enter your password, and once you confirm, it will download and install the MySQL server package along with any necessary dependencies.
sudo apt-get install mysql-server

Start MySQL

sudo systemctl start mysql

This command is used to start the MySQL service on a system running systemd, which is a system and service manager for Linux.

Here’s what each part of the command does:

  • sudo: This prefix grants temporary administrative privileges to the command that follows it. It allows the user to execute the subsequent command with superuser (root) privileges.
  • systemctl: This is a command-line utility used to manage systemd, which is a system and service manager for Linux operating systems. It allows users to start, stop, enable, disable, and manage services and other units.
  • start: This subcommand of systemctl instructs systemd to start the specified service. In this case, mysql refers to the MySQL service.

Next, to access the MySQL CLI(Command Line Interface), you can use the command below in the terminal:

sudo mysql -u root -p

Here’s what each part of the command does:

  • mysql: This is the command used to launch the MySQL command-line interface.
  • -u root: This option specifies the username to use when connecting to the MySQL server. In this case, it specifies that the root user should be used.
  • -p: This option prompts the user to enter the password for the specified MySQL user (in this case, the root user). After entering the password, if it’s correct, the user gains access to the MySQL CLI with administrative privileges.

Create db

Create a new database world using the command below in the terminal

create database world;

Connect to db

use world;

Complete DB w Scripts

  • Use the script files we downloaded above
source world_mysql_script.sql;

Show Table

SHOW TABLES:

Show Records

SELECT * FROM city WHERE countrycode='CAN';

Update Table with Update Script

source world_mysql_update_A.sql;

Show Records to verify

SELECT * FROM city WHERE countrycode='CAN';

Quit db

\q