Unlike Windows, Unix family operating systems including Linux and BSD are open-source and free in addition to the focus on using the terminal instead of graphical user interfaces (UIs).
Linux is part of Unix OSs and Ubuntu is a debian-based distribution of Linux. Linux is to Windows what manual cars are to the automatic ones. It offers more security and low-level access to the hardware and I/Os which makes it preferable to developers. Windows updates and idiotic releases are a headache for everyone and there seems to be no promising solutions in the future.
Working with Linux might seem a bit confusing and unnatural at first, but once you get hands on commands and features, you'll realize the benefits and perks of using a Unix-based OS for your system and development.
Download Ubuntu desktop image file from here. Search "create and format hard disk partitions" on your Windows search bar. Right click on your C: volume and select shrink volume.
Enter your desired space in MB and click OK.
Burn the Ubuntu 20 image on a USB with Rufus prefrably. Restart your Windows and keep pressing "Del" or "F11" to enter BIOS settings (the BIOS buttons might differ on your system). Once in BIOS settings, change the boot priority to USB and then save and reboot.
Click on "Install Ubuntu". Select your language and then choose "Normal Installation" on "Updates and other software" tab.
Over "Installation Type" tab select "something else".
Click on "free space":
Then click on + button. Type "/" for "Mount point" and then click ok and then install.
Download VMWare Workstation Player from the official website. Unlike VMWare Pro, this version is free but only allows one virtual machine.
Select the iso file, choose a username and password and then install the virtual machine.
Open a terminal with:
Ctrl + Alt + T
For opening another terminal on the same page:
Ctrl + Shift + T
Here is a list of useful terminal commands:
$ ls # list current directory
$ ll # detailed directory listing
$ ls -l / # list root directory
$ pwd # display the path name of the working directory
$ cd # change direcotry
$ mkdir # make a directory
$ mv # move a file or directory
Useful shortkeys on a terminal:
Ctrl + Shift + C (copy)
Ctrl + Shift + V (paste)
Ctrl + Shift + R (search for previous commands)
Ctrl + Shift + U (delete current command)
Ctrl + C (interrupt current process)
Ctrl + D (exit current terminal)
Create a file with:
$ touch example.txt
To edit use either:
$ gedit example.txt
Or:
$ vi example.txt
vi commands:
:qw (save and quit)
:q! (quit without saving)
The default python command on Ubuntu terminal is:
$ python3
To change it run:
$ sudo apt install python-is-python3
Now create a python file and run it:
$ touch hello.py
$ echo 'print("hello world")' > hello.py
$ chmod +x hello.py
$ python hello.py
To install pip:
$ sudo apt install python3-pip
To list packages, run:
$ pip list
To install a package, like numpy, simply run:
$ pip install numpy
Developing and building C++ files are pretty chill on Linux. First you should install CMake:
$ sudo apt update
$ sudo apt install cmake
Make sure cmake is installed:
$ cmake --version
Now create a new foler in Documents directory:
$ cd /Documents
$ mkdir C++
Create a cpp file:
$ touch main.cpp
Write your code here:
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello Linux! \n";
return 0;
}
Now create your CMakeList.txt file:
$ touch CMakeLists.txt
And write:
cmake_minimum_required(VERSION 3.16.3)
project(HELLOLINUX VERSION 1.0)
add_executable(${PROJECT_NAME} main.cpp)
g++ -g -c -Wa,-alh main.cc > main.s
Now you have to create configure.sh, build.sh and run.sh bash files:
$ touch configure.sh
No write the following commands into configure.sh:
#!/bin/sh
cmake -S . -B out/build
$ touch build.sh
No write the following commands into build.sh:
#!/bin/sh
cd out/build ; make
$ touch run.sh
No write the following commands into build.sh:
#!/bin/sh
cd out/build ; ./HELLOLINUX
Make bash files executable:
$ chmod +x configure.sh build.sh run.sh
Now run:
$ ./configure.sh
$ ./build.sh
$ ./run.sh
Setting up Git is crucial for organizing your codes and version control. To install Git:
$ sudo apt install git
To clone a repository, simply run:
$ git clone [email protected]:roboticswithamir/linux_tutorials.git
You cannot directly make changes to repositories where you don't have developer access. To do so, you have to fork a repository first and then clone the fork one. So, you can simply access this repo over here and then click on fork. Now clone your forked repo in a new folder. Before committing your changes, you have to add your ssh key to your github or gitlab account. To do so, first generate a ssh key:
$ cd
$ ssh-keygen
Now read the key by running:
$ cat .ssh/id_rsa.pub
Copy the key into your github account by going to settings/SSH and GPG keys and add click on "New ssh key" and copy your key there.
You can now make changes and add all files to git by:
$ git add .
Then make a commit:
$ git commit -m "Add main.c"
And push it:
$ git push
SSH offers secure and reliable access to a remote linux station or even a local one as a virtual machine. With SSH, one can simply develop codes over a local IDE or code editor on a Windows or other OS. SSH is installed by default on Ubuntu, however, it's needed to install ssh server as:
$ sudo apt install openssh-server
Then run:
$ sudo service ssh start
$ sudo service ssh status
For establishing an ssh, you need to have your host IP address. Install net-tools package:
$ sudo apt install net-tools
And run:
$ ifconfig
Now you can SSH into your host by running the following command on your desired terminal on Windows shell or anywhere else:
$ ssh usename@ip
ssh -J B C
ssh -o ProxyCommand='ssh -W %h:%p B' C
If you need this every time you ssh from A to C it can be useful to add an entry in your .ssh/config file looking like this (in recent versions):
Host target
ProxyJump proxy@proxy_ip
HostName target_ip
User target_user
To perform an automated task with crontab, use the following command to start editing the default crontab file:
crontab -e
To get a list of the current tasks:
crontab -l
Crontab command format:
# 0 0 * * * /home/user/automate.sh >> /home/user/log.txt
To run a shell as root simply run:
sudo -i
Setup the .bashrc to prevent conda from being activate in every shell, hwoever, activate easily by "activate conda".
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
# __conda_setup="$('/home/$USER/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
# if [ $? -eq 0 ]; then
# eval "$__conda_setup"
# else
# if [ -f "/home/$USER/miniconda3/etc/profile.d/conda.sh" ]; then
# . "/home/$USER/miniconda3/etc/profile.d/conda.sh"
# else
# export PATH="/home/$USER/miniconda3/bin:$PATH"
# fi
# fi
# unset __conda_setup
# <<< conda initialize <<<
if [ -f "/home/$USER/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/$USER/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/$USER/miniconda3/bin:$PATH"
fi
sudo snap install vlc
sudo apt-get install ubuntu-restricted-extras
TODO
TODO
# Example installation steps
$ git clone https://github.com/username/project.git
$ cd project
$ npm install
Multiline example:
function exampleFunction()
{
return 'Hello, World!';
}
# Example installation steps
$ sudo apt search