Category Archives: Linux

Basic Linux commands

How to check if a file exists on the filesystem.

To check whether a file exists in a Linux filesystem, we can deploy the use of the following commonly used file operators, that is -e and -f

-e will check whether a file exists regardless of the type, and will return true if any type of file exists.

-f will only return true only if the file is a regular file I.e, not a directory or a device.

We use the following syntax

test -e filename
[ e filename ]
test -f filename
[ -f filename ]

An example. Let’s check if we have a filename called shell in the /etc/ directory.

[ -e /etc/shell ] && echo “Found” || echo “Not Found”
[ -f etc/shell ] && echo “Found” || echo “Not Found”

If you run the following you will get an answer, if there is a file matching what you have specified then it will echo Found and if the file is not available it will echo not found.

Find the 50th line of a file using tail and head commands.

The Head command will always output the first 10 items on the file while the Tail command will print the last 10 items in the file.

If you want to find the 50th line of a file, we need to combine the two, tail and head commands.

Let’s say I have a spreadsheet called students.csv and this list contains 800 students, to display the 50th student we use the following command.

Tail -n +50 students.csv | head -n 1

head -n 50 students.csv | tail -n 1

-n shows the nth line

+50 tells us to print from line 50. This is an option to be used with the tail command.

Head -n 1 will tell us to print the first line only and that is the 50th line. If you want to print the first 5 lines you use head -n 5 or tail -n 5

How to copy a file from one Linux machine to another

To copy a file from one Linux machine to another, use scp command which is the secure copy command. The command will look like this:

scp  user@host: 

The filename is the file you want to copy to the remote machine

The user is the destination username

The host is the destination host, and the best way to determine the host is to use the IP address of that host.

The file destination is the directory you want your file to be sent to.

Let’s see an example, We have a file called students.csv on the local machine, to transfer this file we use the following command.

scp students.csv root@97.107.132.178:/remote/directory

This will prompt you to authenticate, fill in your password and you are good to go

If you check on your remote server you will see the students.csv file

To copy a directory to a remote machine we use the following command.

scp -r test root@97.107.132.178:/remote/directory

The test is the directory I want to copy.

How to monitor a continuously updating log file

The most effective tool to manage continuously changing log files is the tail command.

The tail command shows the last 10 commands when used, in this case, if logs are continuously changing we can use the tail with -f option will print to the terminal any new lines added to the log file in real-time.

Let’s take an example, we need to monitor apache2, this is how we can see the most recent logs.

Tail -f

sudo tail -f /var/log/apache2/access.log

With this command, we will be in a position to get the latest logs as it occurs.

How to install Webmin 2 control panel on Ubuntu 22.04

In this tutorial, we will learn how to install the Webmin control panel on Ubuntu 22.04

Webmin is a powerful and flexible web-based server management control panel for UNIX-like users. It allows Webmin to configure operating system internals e.g users, configuration files, disk quotas, etc. Webmin removes the need to edit Unix configuration files manually and lets you manage the system remotely or via console.

Install Webmin on Ubuntu 22.04

Let’s install Webmin via Ubuntu apt repository. First, update your system in order to make them up to date.

sudo apt update && apt upgrade

To install Webmin via apt repository, we need to edit the /etc/apt/sources.list file and add the following line deb https://download.webmin.com/download/repository sarge contrib

sudo vi /etc/apt/sources.list

Secondly, let’s add GPG key with which the repository is signed.

wget https://download.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc

Third, we need to update our system repositories again for the changes to be effected.

sudo apt update 

Finally, install the Webmin with the following command.

sudo apt install webmin -y

You should be in a position to see an output like this

The following additional packages will be installed:
  libauthen-pam-perl libio-pty-perl libnet-ssleay-perl perl-openssl-defaults
  unzip
Suggested packages:
  zip
The following NEW packages will be installed:
  libauthen-pam-perl libio-pty-perl libnet-ssleay-perl perl-openssl-defaults
  unzip webmin
0 upgraded, 6 newly installed, 0 to remove and 2 not upgraded.
Need to get 29.0 MB of archives.
After this operation, 305 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

To know that the Webmin was installed correctly, check the version with the following command.

webmin -v
2.000

Having successfully installed Webmin, let’s now go to the browser and see the Webmin in action.

http://:10000

The username is the root and the password is the root user password.

You should be in a position to see a dashboard like this.

Nextgentips: Webmin dashboard

How to install and setup SFTP server on Ubuntu 22.04

SFTP (Secure File Transfer Protocol) is a file transfer protocol that provides secure access to a remote computer. Think of it as a tunnel provider, whenever you want to connect remotely, you use SFTP protocol to ensure your connection is secure from eavesdropping, we use Secure Shell (SSH) for that.

FTP protocol is a client/server protocol that transfers files over the internet. FTP clients are used to sending and retrieving files to and from servers storing files and also responding to the clients’ needs.

To get started with the installation, make sure ssh is installed, then set up sftp user group, configure ssh service, and lastly connect via sftp service.

1. Update system repositories.

To start off, update your system repositories in order to make them up to date.

sudo apt update && apt upgrade -y

2. Install ssh server

SFTP depends on ssh protocol for communication, we have to install it if not already installed on your system.

sudo apt install ssh 

The following will be the sample output.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  ssh
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 4834 B of archives.
After this operation, 133 kB of additional disk space will be used.
Get:1 http://mirrors.linode.com/ubuntu jammy/main amd64 ssh all 1:8.9p1-3 [4834 B]
Fetched 4834 B in 0s (199 kB/s)
Selecting previously unselected package ssh.
(Reading database ... 108902 files and directories currently installed.)
Preparing to unpack .../ssh_1%3a8.9p1-3_all.deb ...
Unpacking ssh (1:8.9p1-3) ...
Setting up ssh (1:8.9p1-3) ...
Scanning processes...                                                           
Scanning candidates...                                                          
Scanning linux images...                                                        

Restarting services...
Service restarts being deferred:
 /etc/needrestart/restart.d/dbus.service
 systemctl restart networkd-dispatcher.service
 systemctl restart systemd-logind.service
 systemctl restart unattended-upgrades.service
 systemctl restart user@0.service

If you want to install FTP over OpenSSH, you need to edit the sshd configuration file.

sudo vim /etc/ssh/sshd_config

You will need to add this below the file.

Match group sftp
ChrootDirectory /home
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

Restart the ssh server for the changes to take effect.

sudo systemctl restart ssh

3. Create SFTP user account.

Set up STTP user and group which will log in here.

To set the group use the following command.

$ sudo addgroup sftpgroup
Adding group `sftpgroup' (GID 1000) ...
Done.

Then we need to create sftpuser and you need to assign it to sftp group

sudo useradd -m sftpuser -g sftpgroup

Set the password for sftpuser.

$ sudo passwd sftpuser
New password: 
Retype new password: 
passwd: password updated successfully

Lastly, grant the new user access home directory.

sudo chmod 700 /home/sftpuser/

4. Connect to sftp

To connect to sftp we use the command

$ sftp sftpuser@localhost

For instance, to login to the sftp I have created, I need to type sftp sftpuser@127.0.0.1

$ sftp sftpuser@127.0.0.1
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ED25519 key fingerprint is 
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '127.0.0.1' (ED25519) to the list of known hosts.
sftpuser@127.0.0.1's password: 
Connected to 127.0.0.1.
sftp> 
sftp> 

5. Useful SFTP commands

Whenever you need help with any command using the following command.

sftp> help

If you want to navigate through your SFTP, use pwd

sftp> pwd
Remote working directory: /home/sftpuser

To download files with sftp command.

sftp> get filename.zip

Conclusion

We have successfully installed sftp on Ubuntu 22.04, happy learning.

How to perform CRUD functionalities in Django Rest Framework

Django Rest framework is a powerful toolkit for building web APIs.

What is an API?

An API (Application Programming Interface) is a set of rules shared by a particular service. These rules determine in which format and with which command set your application can access the service, as well as what data this service can return in the response. It acts as a layer between your application and external service.

REST API (Representational state transfer) is an API that uses HTTPS requests for communication with web services. From the python site, the REST API can be viewed as a data source located on an internet address that can be accessed in a certain way through certain libraries.

Types of Requests:

GET: retrieve information like a search result

POST: adds new data to the server

PUT: changes existing information

DELETE: deletes existing information

Status Codes

200-OK. The request was successful.

204-No content. The server successfully processed the request and did not return any content.

301-Moved permanently. The server responds that the requested page(endpoint) has been moved to another address and redirects to this address.

400-Bad request. The server cannot process the request because of the client-side errors (incorrect request format).

401-Unauthorized. Occurs when authentication failed due to incorrect credentials or even their absence.

403-Forbidden. Access to the specified resource is denied.

404-Not found. The requested resource was not found on the server.

500-Internal Server Error. Occurs when an unknown error has occurred on the server.

Enough with the theory part. Let’s see how we can create CRUD functionalities in the Django Rest framework.

I will create a small to-do list application to guide us through the process.

Steps to follow.

  1. Create a project and set up a virtual environment.
  2. Activate virtual environment
  3. Install Django using pip
  4. Create a project and an app

Create a Django Project and set up a virtual environment.

The first thing to do whenever you are creating Django projects is to set up your virtual environment where you can work in isolation. Let’s start. Install venv package to allow you to create a virtual environment. On your terminal use the following command to create virtual environment.

$ python3 -m venv env 

If you ls you will see your environment created. For my case, I created env as my environment.

To activate your environment, use the following command.

source env/bin/activate

After the environment is activated, let’s install Django using the pip command.

pip install django

Create a requirements.txt file to store all your installations so that the next time someone is using your applications, it will be easy to start off. An easy way to create requirements is to use the freeze command.

pip freeze > requirements.txt

And to do an installation from the requiremets.txt file, use the following command.

pip install -r requiremets.txt

Create a Django Project

To create a Django project, we use the following command.

django-admin startproject myapi .

Take note of the period in the end, it will help create a project from the current directory.

After this is done, create an app.

python manage.py startapp todoapi

The last thing before we can start our server is to go to settings.py and add your created app to the installed apps section. From here the best thing is to open your project using Visual Studio or Pycharm. For me, I will be using Pycharm.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    
    'todoapi',# our app
]

From here you can test if the server is running

python manage.py runserver

if you see the following as output, then we are good to continue.

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
July 13, 2022 - 07:03:07
Django version 4.0.6, using settings 'myapi.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Go to the given IP address to see the outcome.

Let’s render something rather than the default Django output by adding our app to the projects urls.py section.

#myapi.urls
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('todoapi.urls')), # add this todoapi.urls 
]

Also to keep our URLs neat and tidy, go to todoapi and create a urls.py

#todoapi urls.py
from django.urls import path
from . import views 

urlpatterns = [
    path('', views.home, name='home'),
]

Go to todoapi views.py and create the first view of our rest API.

#todoapi/views.py
from django.shortcuts import render
from django.http import HttpResponse


def home(request):
    return HttpResponse("My first api")

You are supposed to see “my first API from the browser”. This means we are good to create our API now.

Create Django Rest API

To start creating a rest API, you need to install djangorestframework and add it to your installed apps in the settings.py

pip install djangorestframework

Then you need to add it to your installed apps

INSTALLED_APPS = [
    ...
    'rest_framework',
]

Also you can add it to your requirements.txt file

pip freeze > requirements.txt 

To begin with, we are going to use function based views therefore we need decorators. For function based views, we use @api_view.

Go to models.py and add the following

#todoapi models.py
from django.db import models


class Todo(models.Model):
    title = models.CharField(max_length=150)
    completed = models.BooleanField(blank=True, null=True, default=False)

    def __str__(self):
        return self.title

To begin, lets create a serializers.py file in our todoapi app first.

#todoapi serializers.py
from rest_framework import serializers

from todoapi.models import Todo


class TodoSerializer(serializers.ModelSerializer):
    class Meta:
        model = Todo
        fields = '__all__'

You need to make migrations for the serializer tables to be created.

$ python manage.py makemigrations
$ python manage.py migrate 

From here you can create admin account so that you can insert the test data. to create admin panel use the following command.

$ python manage.py createsuperuser
Username (leave blank to use 'nextgen'): admin
Email address: 
Password: 
Password (again): 
Superuser created successfully.

The next thing is to register admin in the admin dashboard. use the following.

from django.contrib import admin

# Register your models here.
from todoapi.models import Todo

admin.site.register(Todo)

Running CRUD operations

List Request

To start performing CRUD operations, lets start with the List Operations, this will show all the todos we have in our database. List is a GET operations, so make sure to add that

Go to views.py and add the following.

@api_view(['GET'])
def list_view(request):
    todos = Todo.objects.all()
    serializer = TodoSerializer(todos, many=True)
    return Response(serializer.data, status=status.HTTP_200_OK)

Create a url corresponding to the above view.

path('todo-list/', views.list_view, name='todo-list')

Detail Request

The next thing is to create a detail view, also we are going to use GET to retrieve data.

@api_view(['GET'])
def detail_view(request, pk):
    todo = Todo.objects.get(id=pk)
    serializer = TodoSerializer(todo, many=False)
    return Response(serializer.data)

Note we are using primary key to retrieve specific item.

Create corresponding url for detail view set.

path('detail-view//', views.detail_view, name='detail-view')

Create Request

Here we are using POST to post data into the database. Use the following code

@api_view(['POST'])
def create_view(request):
    serializer = TodoSerializer(data=request.data)

    if serializer.is_valid():
        serializer.save()
    return Response(serializer.data, status=status.HTTP_201_CREATED)

Add corresponding url path

 path('create-todo/', views.create_view, name='create-todo'),

For testing purposes you can use Insomnia or postman or you can stick to the one provided once you access the API on your browser.

Update request

To update a given request we use POST method. use the following code.

@api_view(['POST'])
def update_view(request, pk):
    todo = Todo.objects.get(id=pk)
    serializer = TodoSerializer(instance=todo, data=request.data)

    if serializer.is_valid():
        serializer.save()
    return Response(serializer.data, status=status.HTTP_202_ACCEPTED)

Add corresponding url path

path('update-todo//', views.update_view, name='update-todo'),

Delete request

To use delete request, DELETE options is called. Use the following code.

@api_view(['DELETE'])
def delete_view(request, pk):
    todo = Todo.objects.get(id=pk)
    todo.delete()
    return Response("Todo deleted successfully", status=status.HTTP_204_NO_CONTENT)

Add corresponding url path accordingly.

path('delete-todo//', views.delete_view, name='delete-todo'),

Conclusion

We have successfully performed CRUD operations on Django Rest API. To take it further you can use swaggerUI to visualize your API or you can connect to any frontend libraries such React, Vue, Svelte or use Vanilla Javascript.

How to install Python Pip on Ubuntu 22.04

In this tutorial, you will learn how to install Python pip on Ubuntu 22.04.

Pip is a package management system written in Python and is used to install and manage software packages. It connects to an online repository of public packages called the Python Package Index. It can also be configured to connect to other package repositories.

Usually, Pip is automatically installed while working in a virtual environment, and also if you are using Python that has not been modified by the redistributor to remove ensure pip.

Pip is recommended tool for installing Python packages. For you to start using pip, you need to have python3 installed on your system.

Installing Python pip on Ubuntu 22.04

You can install pip either through a virtual environment or while installing Python. It depends on which one you prefer. I will be using a virtual environment to install pip on Ubuntu 22.04.

1. Run system updates

First, we need to update our repositories to make them up to date by issuing update and upgrade commands on our terminal.

$ sudo apt update && apt upgrade -y

2. Create a virtual environment

A virtual environment is used to manage Python packages for different projects. It creates an isolated environment for pip packages.

Begin by creating a directory where your virtual environment will be located.

$ sudo mkdir nextgen
$ cd nextgen

Next, create a virtual environment

$ python3 -m venv env

env is the name given to a virtual environment.

In case you encounter the following error, follow the instruction in order to make necessary changes.

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.10-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/root/nextgen/env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

Correct this error by running

sudo apt install python3.10-venv

From the above, you will see the following output.

The following additional packages will be installed:
  python3-pip-whl python3-setuptools-whl
The following NEW packages will be installed:
  python3-pip-whl python3-setuptools-whl python3.10-venv
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 2473 kB of archives.
After this operation, 2882 kB of additional disk space will be used.
Do you want to continue? [Y/n] 

The next thing is to run python3 -m venv env again.

sudo python3 -m venv env

You need to activate the virtual environment to start using it.

$ source env/bin/activate 
(env) root@localhost:~/nextgen# 

Now that we have activated the virtual environment, you can now check if pip has been installed, because pip is installed while creating the virtual environment.

pip --version
pip 22.0.2 from /root/nextgen/env/lib/python3.10/site-packages/pip (python 3.10)

Conclusion

We have learned how to install pip on Ubuntu 22.04 because this is the starting point for any python programming. I am glad you have enjoyed the tutorial. Feel free to comment in case you are faced with a challenge.

How to install PHP 8.1 on Ubuntu 22.04

In this tutorial, we will learn how to install the current stable release version of PHP 8.1 on Ubuntu 22.04.

PHP is a general-purpose scripting language suitable for web development. Most websites out there are programmed using PHP language because it is:

  • Fast – PHP is fast because it runs on its own memory space. Also, PHP has a Zend engine that parses PHP code and turns it into opcodes which are then interpreted.
  • Flexible – PHP is flexible because it allows for almost all databases. MySQL is the de-facto database to connect to because it is open source.
  • Free and open source
  • PHP is forgiving – Why do we say PHP is forgiving? It is forgiving, meaning learning is not so hard and therefore suitable to almost all programmers starting out.
  • PHP supports major communication protocols i.e LDAP, IMAP, POP3.

Features of PHP 8.1

PHP 8.1 is a major update release version. It contains many new features and optimizations such as:

  • It introduced the Enumerations feature. Enumerations or Enum feature allow a developer to define a custom type that is limited to one of the discrete numbers of possible values. This is helpful while defining the domain model.
  • Improvement of RFC read-only property version 2. This prevents modification of the property after initialization.
  • The introduction of RFC fibers calls for action. This seeks to eliminate synchronous and asynchronous function calls by allowing functions to become interruptible without affecting the entire function.
  • Introduction of a non-return type. This indicates that a function either exits throws an exception or doesn’t terminate.
  • Introduction of first-class callable actions.
  • Introduction of fsync and fdatasync functions
  • Introduction of array_is_list functions
  • Introduction of explicit octal numeral notation

Installing PHP 8.1 on Ubuntu 22.04

1. Run system updates

The first thing to do in a new system is to update our repositories in order to make them up to date. Run upgrade command also.

$ sudo apt update && apt upgrade -y

2. Add Ondrej Sury PPA repository

To run PHP 8.1 on Ubuntu 22.04, we need to add Ondrej Sury PPA into our system. This is the maintainer of the PHP repository at the moment. This PPA is not currently checked so installing from it will not guarantee 100% results.

To add this PPA use the following command on our terminal.

$ sudo add-apt-repository ppa:ondrej/php

You will see the following as the output.

PPA publishes dbgsym, you may need to include 'main/debug' component
Repository: 'deb https://ppa.launchpadcontent.net/ondrej/php/ubuntu/ jammy main'
Description:
Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.

Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org

IMPORTANT: The -backports is now required on older Ubuntu releases.

BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting

CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
   or ppa:ondrej/nginx

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Adding deb entry to /etc/apt/sources.list.d/ondrej-ubuntu-php-jammy.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/ondrej-ubuntu-php-jammy.list
Adding key to /etc/apt/trusted.gpg.d/ondrej-ubuntu-php.gpg with fingerprint 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C
Hit:1 http://mirrors.linode.com/ubuntu jammy InRelease
Hit:2 http://mirrors.linode.com/ubuntu jammy-updates InRelease                 
Hit:3 http://mirrors.linode.com/ubuntu jammy-backports InRelease               
Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease               
Get:5 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy InRelease [23.9 kB]
Get:6 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy/main amd64 Packages [92.9 kB]
Get:7 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy/main Translation-en [29.1 kB]
Fetched 146 kB in 2s (68.5 kB/s)                                 
Reading package lists... Done

You need to update your system repositories again for the changes to take effect.

sudo apt update 

Install PHP 8.1 on Ubuntu 22.04

After you have updated your system, it’s now time to run the installation, with the following command.

sudo apt install php8.1 -y

You will be in a position to see the following as output.

The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.1 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 php-common
  php8.1-cli php8.1-common php8.1-opcache php8.1-readline ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
  php-pear
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.1 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 php-common
  php8.1 php8.1-cli php8.1-common php8.1-opcache php8.1-readline ssl-cert
0 upgraded, 17 newly installed, 0 to remove and 1 not upgraded.
Need to get 7227 kB of archives.
After this operation, 29.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Now we can check to see the version of PHP installed

php --version
PHP 8.1.7 (cli) (built: Jun 25 2022 08:13:46) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.7, Copyright (c), by Zend Technologies

Conclusion

We have learned how to install PHP 8.1 on Ubuntu 22.04, now you can proceed to write your programs using this awesome language. Consult PHP documentation in case you experience any difficulty. Happy coding!

How to install Visual Studio Code on Opensuse 15.4

In this article, we are going to learn how to install Visual Studio code also known as (VScode) on Opensuse 15.4. Visual Studio Code is a lightweight source code editor that runs on desktops and is available to all operating systems. It comes with built-in Javascript, Node.js, and Typescript. One can do programming for almost languages with ease with Visual Studio Code. The languages supported are, Go, PHP, C++, C#, Java, Python, and also .NET.

Why do we like Visual Studio Code?

The reason VS code is such an excellent tool is because of the following reasons:

  • It is available on all operating systems so it does not limit one on where to run the VS code, you can easily hit the ground running.
  • Vscode has a rich built-in developer tooling for example IntelliSense code completion and debugging which become handy when you do not know the complete code snippet. It acts as a guide and also takes less time to code.
  • VScode can be customized to suit your needs. You can customize every feature the way you wish and also you can add third-party extensions easily.
  • VScode is an open-source project. So it means you can contribute to the project development, also it means that you have a bigger community where you can ask questions whenever you are faced with a problem.
  • VScode is built for the web. It includes great tools for web development such React JSx, JSON, SCSS,CSS, HTML and Less.

Install Visual Studio code on Opensuse 15.4

1. Update system repositories

Begin by updating system repositories in order to make them up to date.

$ sudo zypper update

2. Add key to the repository

Currently, the Visual studio code ships a 64-bit version. So let’s import the key to sign our repository using the following command.

$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

After you have imported the key, add Visual studio code to the yum repositories.

$ sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/vscode.repo'

The next thing is to update your system repositories for the changes to be effected.

$ sudo zypper refresh

3. Install Visual Studio code on Opensuse 15.4

To install Visual Studio code run the following command on your terminal.

$ sudo zypper install code

You should get something like this.

# output
The following 27 recommended packages were automatically selected:
  adobe-sourcecodepro-fonts adwaita-icon-theme cantarell-fonts gcr-ssh-agent
  gcr-viewer gnome-online-accounts gtk3-branding-openSUSE gtk3-immodule-amharic
  gtk3-immodule-inuktitut gtk3-immodule-thai gtk3-immodule-tigrigna
  gtk3-immodule-vietnamese gvfs gvfs-backends gvfs-fuse libfreebl3-hmac
  libsoftokn3-hmac libudisks2-0_btrfs notification-daemon perl-HTTP-Message
  perl-libwww-perl perl-LWP-Protocol-https perl-TimeDate postfix
  sound-theme-freedesktop udisks2 xkeyboard-config-lang

The following 292 NEW packages are going to be installed:
  adobe-sourcecodepro-fonts adwaita-icon-theme atk-lang at-spi2-atk-common
  at-spi2-atk-gtk2 at-spi2-core at-spi2-core-lang bubblewrap cantarell-fonts
  code cryptsetup cryptsetup-lang cups-config dconf desktop-translations
  dosfstools enchant-2-backend-hunspell enchant-data expat fontconfig
  fontconfig-lang fuse3 gcr-data gcr-lang gcr-prompter gcr-ssh-agent gcr-viewer
  gdk-pixbuf-lang gdk-pixbuf-loader-rsvg gdk-pixbuf-query-loaders
  gdk-pixbuf-thumbnailer gio-branding-openSUSE glib2-tools glib-networking
  glib-networking-lang gnome-online-accounts gnome-online-accounts-lang
  gsettings-backend-dconf gsettings-desktop-schemas
  gsettings-desktop-schemas-lang gstreamer gstreamer-lang gstreamer-plugins-base
  gstreamer-plugins-base-lang gtk2-branding-openSUSE gtk2-data
  gtk2-immodule-amharic gtk2-immodule-inuktitut gtk2-immodule-thai
  gtk2-immodule-tigrigna gtk2-immodule-vietnamese gtk2-lang
  gtk2-metatheme-adwaita gtk2-theming-engine-adwaita gtk2-tools
  gtk3-branding-openSUSE gtk3-data gtk3-immodule-amharic gtk3-immodule-inuktitut
  gtk3-immodule-thai gtk3-immodule-tigrigna gtk3-immodule-vietnamese gtk3-lang
  gtk3-metatheme-adwaita gtk3-schema gtk3-tools gvfs gvfs-backend-afc
  gvfs-backends gvfs-fuse gvfs-lang json-glib-lang libaom3 libarchive13
  libasound2 libatasmart4 libatasmart-utils libatk-1_0-0 libatk-bridge-2_0-0
  libatspi0 libavahi-client3 libavahi-common3 libavahi-glib1 libavif13
  libbd_btrfs2 libbd_crypto2 libbd_fs2 libbd_loop2 libbd_lvm2 libbd_mdraid2
  libbd_part2 libbd_swap2 libbd_utils2 libblockdev libblockdev2 libbluray2
  libbytesize1 libbytesize-lang libcairo2 libcairo-gobject2 libcdda_interface0
  libcdda_paranoia0 libcdio16 libcdio19 libcdio_cdda2 libcdio_paranoia2
  libcolord2 libcups2 libdatrie1 libdav1d5 libdconf1 libdrm2 libenchant-2-2
  libepoxy0 libevdev2 libexif12 libfontconfig1 libfreebl3 libfreebl3-hmac
  libfribidi0 libfuse3-3 libgbm1 libgck-1-0 libgcr-3-1 libgd3 libgdata22
  libgdata-lang libgdk_pixbuf-2_0-0 libgio-2_0-0 libglvnd libgoa-1_0-0
  libgoa-backend-1_0-1 libgobject-2_0-0 libgphoto2-6 libgphoto2-6-lang
  libgraphene-1_0-0 libgraphite2-3 libgstallocators-1_0-0 libgstapp-1_0-0
  libgstaudio-1_0-0 libgstfft-1_0-0 libgstgl-1_0-0 libgstpbutils-1_0-0
  libgstreamer-1_0-0 libgstriff-1_0-0 libgsttag-1_0-0 libgstvideo-1_0-0
  libgtk-2_0-0 libgtk-3-0 libgudev-1_0-0 libharfbuzz0 libharfbuzz-icu0
  libhunspell-1_6-0 libhyphen0 libicu65_1-ledata libicu-suse65_1
  libimobiledevice-1_0-6 libimobiledevice-glue-1_0-0 libinih0
  libjavascriptcoregtk-4_0-18 libjbig2 libjpeg8 libjson-glib-1_0-0 liblcms2-2
  liblmdb-0_9_17 liblockdev1 libltdl7 liblvm2cmd2_03 libmanette-0_2-0
  libmozjs-60 libmtp9 libmtp-udev libnfs8 libnotify4 liboauth0 libogg0
  libopenjp2-7 libopus0 liborc-0_4-0 libpango-1_0-0 libpixman-1-0 libplist-2_0-3
  libpolkit0 libpwquality1 libpwquality-lang librav1e0 librest-0_7-0 librsvg-2-2
  libsecret-1-0 libsecret-lang libsoftokn3 libsoftokn3-hmac libsoup-2_4-1
  libsoup2-lang libthai0 libthai-data libtheoradec1 libtheoraenc1 libtiff5
  libudisks2-0 libudisks2-0_btrfs libunwind libusbmuxd-2_0-6 libvisual
  libvorbis0 libvorbisenc2 libwayland-client0 libwayland-cursor0 libwayland-egl1
  libwayland-server0 libwebkit2gtk3-lang libwebkit2gtk-4_0-37 libwebp7
  libwebpdemux2 libwoff2common1_0_2 libwoff2dec1_0_2 libwpe-1_0-1
  libWPEBackend-fdo-1_0-1 libX11-xcb1 libxcb-render0 libxcb-shm0 libXcomposite1
  libXcursor1 libXdamage1 libXext6 libXfixes3 libXft2 libXi6 libXinerama1
  libxkbcommon0 libxkbfile1 libXpm4 libXrandr2 libXrender1 libXtst6 libXv1
  lockdev lvm2 mdadm metatheme-adwaita-common mozilla-nspr mozilla-nss
  mozilla-nss-certs notification-daemon notification-daemon-lang
  openssh-askpass-gnome perl-CPAN-Changes perl-Devel-Symdump perl-Encode-Locale
  perl-File-Listing perl-HTML-Parser perl-HTML-Tagset perl-HTTP-Cookies
  perl-HTTP-Daemon perl-HTTP-Date perl-HTTP-Message perl-HTTP-Negotiate
  perl-IO-HTML perl-IO-Socket-SSL perl-libwww-perl perl-LWP-MediaTypes
  perl-LWP-Protocol-https perl-Net-DBus perl-Net-HTTP perl-Net-SSLeay
  perl-Pod-Coverage perl-Test-Pod perl-Test-Pod-Coverage perl-TimeDate
  perl-Try-Tiny perl-URI perl-WWW-RobotRules perl-X11-Protocol perl-XML-Parser
  perl-XML-Twig polkit polkit-default-privs postfix shared-mime-info
  shared-mime-info-lang sound-theme-freedesktop system-user-lp system-user-mail
  udisks2 udisks2-lang usbmuxd webkit2gtk-4_0-injected-bundles xdg-dbus-proxy
  xdg-utils xfsprogs xkeyboard-config xkeyboard-config-lang

292 new packages to install.
Overall download size: 210.0 MiB. Already cached: 0 B. After the operation,
additional 695.1 MiB will be used.
Continue? [y/n/v/...? shows all options] (y):

4. Uninstall Visual Studio code.

To remove visual studio code from your system, use the following command.

The following package is going to be REMOVED:

1 package to remove.
After the operation, 332.6 MiB will be freed.
Continue? y/n/v/…? shows all options: y
(1/1) Removing code-1.68.1-1655263151.el7.x86_64 …………………….[done]

How to install Visual Studio Code on Fedora 36

In this article we are going to learn how to install Visual Studio code also know as (VScode) on Fedora 36. Visual Studio Code is a lightweight source code editor which runs on desktops and is available to all operating systems out there. It comes with built in Javascript, Node.js and Typescript. One can do programming for almost languages with ease with Visual Studio Code. The languages supported are like, Go, PHP, C++, C#, Java, Python and also .NET.

Why do we like Visual Studio Code?

The reason VS code is such a nice tool is because of the following reasons:

  • It is available on all operating systems so it does not limit one on where to run the VS code, you can easily hit the ground running.
  • Vscode has a rich build-in developer tooling for example IntelliSense code completion and debugging which become handy when you don not know the complete code snippet. IT acts a guide and also lessen time to code.
  • VScode can be customized to suit your needs. You can customize every feature the way you wish and also you can add third party extensions easily.
  • VScode is an open source project. So it means you can contribute to the project development, also it means that you have a bigger community where you can ask questions whenever you are faced with problem.
  • VScode is built for the web. It includes great tools for web development such React JSx, JSON, SCSS,CSS, HTML and Less.

Install Visual Studio code on Fedora 36

1. Update system repositories

In order not to run into any errors during your installation, you need to update your system repositories in order to make them up to date.

$ sudo dnf update

2. Add key to the repository

Currently the Visual studio code ships 64 bit version using the yum repository. So lets import the key to sign our repos using the following command.

$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

After you have imported the key, add Visual studio code to the yum repositories.

$ sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'

The next thing is to update your system repositories for the changes to be effected.

$ sudo dnf check-update 
Visual Studio Code                               38 MB/s |  26 MB     00:00    
Last metadata expiration check: 0:00:06 ago on Mon Jul  4 07:50:47 2022.

3. Install Visual Studio code on Fedora 36

To install Visual studio code run the following command on your terminal.

$ sudo dnf install code 

You should get something like this.

# output
Installing:
 code                    x86_64 1.68.1-1655263151.el7             code    112 M
Installing dependencies:
 adwaita-cursor-theme    noarch 42.0-1.fc36                       fedora  622 k
 adwaita-icon-theme      noarch 42.0-1.fc36                       fedora  4.2 M
 alsa-lib                x86_64 1.2.7.1-1.fc36                    updates 502 k
 at-spi2-atk             x86_64 2.38.0-4.fc36                     fedora   86 k
 at-spi2-core            x86_64 2.44.1-1.fc36                     updates 178 k
 atk                     x86_64 2.38.0-1.fc36                     fedora  272 k
 avahi-glib              x86_64 0.8-15.fc36                       fedora   15 k
 cairo                   x86_64 1.17.6-1.fc36                     fedora  675 k
 cairo-gobject           x86_64 1.17.6-1.fc36                     fedora   18 k
 cdparanoia-libs         x86_64 10.2-39.fc36                      fedora   54 k
 colord-libs             x86_64 1.4.6-1.fc36                      fedora  233 k
 cups-libs               x86_64 1:2.4.2-1.fc36                    updates 266 k
 exempi                  x86_64 2.6.0-0.2.20211007gite23c213.fc36 fedora  540 k
 exiv2-libs              x86_64 0.27.5-2.fc36                     fedora  770 k

4. Set Visual studio code as default editor

if you want Visual studio code as your default code editor, you can do so with the help of the following command.

$ xdg-mime default code.desktop text/plain

To start using Visual studio code type code on your terminal.

$ code 

5. Uninstall Visual Studio code

To remove visual studio code from your system, use the following command.

sudo dnf remove code 

How to install Visual Studio Code on Ubuntu 20.04|22.04

In this article we are going to learn how to install Visual Studio code also know as (VScode) on Ubuntu 22.04 Visual Studio Code is a lightweight source code editor which runs on desktops and is available to all operating systems out there. It comes with built in Javascript, Node.js and Typescript. One can do programming for almost languages with ease with Visual Studio Code. The languages supported are like, Go, PHP, C++, C#, Java, Python and also .NET.

Why do we like Visual Studio Code?

The reason VS code is such a nice tool is because of the following reasons:

  • It is available on all operating systems so it does not limit one on where to run the VS code, you can easily hit the ground running.
  • Vscode has a rich build-in developer tooling for example IntelliSense code completion and debugging which become handy when you don not know the complete code snippet. IT acts a guide and also lessen time to code.
  • VScode can be customized to suit your needs. You can customize every feature the way you wish and also you can add third party extensions easily.
  • VScode is an open source project. So it means you can contribute to the project development, also it means that you have a bigger community where you can ask questions whenever you are faced with problem.
  • VScode is built for the web. It includes great tools for web development such React JSx, JSON, SCSS,CSS, HTML and Less.

Related Content

  • How to install Visual Studio Code on Ubuntu 21.04

Prerequisites

  • Ubuntu 22.04 workstation
  • Command line basics
  • Internet access

Table of Contents

  • Update the system
  • Install Vscode via snap
  • Launch Vscode

Install Visual Studio code

VScode can be installed either from the snap store or downloaded directly from source.

Install visual studio code via .deb package

1. Update System repositories

before you can begin the installation, make sure you run system updates in order to make your repositories up to date.

$ sudo apt update && apt upgrade -y

2. Add repository key

A key is used to sign the Vscode repositories, for automatic updates to occur. So we need to add this signing key to our apt repository first.

First install wget if not already installed in your system.

$ sudo apt install wget gpg
# Add key
$ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg

Once the key has been added, then install, add microsoft vscode to trusted packages.

$ sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/

After this, we need to add Visual studio code to apt repositories using the following script.

$ sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'

Run system updates again to effect the changes in your syatem.

$ sudo apt update 

Install Visual Studio Code on Ubuntu 22.04|20.04

If you have successfully added everything correctly, then the last thing is to run the installer.

$ sudo apt install code 

You should see the following sample output.

#Output 
The following additional packages will be installed:
  adwaita-icon-theme at-spi2-core dconf-gsettings-backend dconf-service
  fontconfig fontconfig-config fonts-dejavu-core gsettings-desktop-schemas
  gtk-update-icon-cache hicolor-icon-theme humanity-icon-theme
  libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0 libavahi-client3
  libavahi-common-data libavahi-common3 libcairo-gobject2 libcairo2 libcolord2
  libcups2 libdatrie1 libdconf1 libdeflate0 libepoxy0 libfontconfig1 libgbm1
  libgdk-pixbuf-2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common
  libgraphite2-3 libgtk-3-0 libgtk-3-bin libgtk-3-common libharfbuzz0b
  libjbig0 libjpeg-turbo8 libjpeg8 liblcms2-2 libpango-1.0-0
  libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 librsvg2-2
  librsvg2-common libsecret-1-0 libsecret-common libthai-data libthai0
  libtiff5 libwayland-client0 libwayland-cursor0 libwayland-egl1
  libwayland-server0 libwebp7 libxcb-render0 libxcb-shm0 libxcomposite1
  libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1 libxkbcommon0
  libxkbfile1 libxrandr2 libxrender1 libxss1 libxtst6 session-migration
  ubuntu-mono x11-common
Suggested packages:
  colord cups-common gvfs liblcms2-utils librsvg2-bin
The following NEW packages will be installed:
  adwaita-icon-theme at-spi2-core code dconf-gsettings-backend dconf-service
  fontconfig fontconfig-config fonts-dejavu-core gsettings-desktop-schemas
  gtk-update-icon-cache hicolor-icon-theme humanity-icon-theme
  libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0 libavahi-client3
  libavahi-common-data libavahi-common3 libcairo-gobject2 libcairo2 libcolord2
  libcups2 libdatrie1 libdconf1 libdeflate0 libepoxy0 libfontconfig1 libgbm1
  libgdk-pixbuf-2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common
  libgraphite2-3 libgtk-3-0 libgtk-3-bin libgtk-3-common libharfbuzz0b
  libjbig0 libjpeg-turbo8 libjpeg8 liblcms2-2 libpango-1.0-0
  libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 librsvg2-2
  librsvg2-common libsecret-1-0 libsecret-common libthai-data libthai0
  libtiff5 libwayland-client0 libwayland-cursor0 libwayland-egl1
  libwayland-server0 libwebp7 libxcb-render0 libxcb-shm0 libxcomposite1
  libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1 libxkbcommon0
  libxkbfile1 libxrandr2 libxrender1 libxss1 libxtst6 session-migration
  ubuntu-mono x11-common
0 upgraded, 74 newly installed, 0 to remove and 0 not upgraded.
Need to get 101 MB of archives.
After this operation, 425 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

Install Visual Studio Code via Snap.

Snap packages can be installed directly from either the command line or through Ubuntu software repository.

Let us first update our system repository with the following command:

$ sudo apt update
$ sudo apt upgrade -y

After the update and upgrade is complete, we can install VScode classic into our system.

$ sudo snap install --classic code 
Output 
# sudo snap install --classic code 
code 6cba118a from Visual Studio Code (vscode✓) installed

We can start Visual Studio code with the following command:

$ code 

Setting Visual Studio code as default editor

To set Vscode as a default editor, Debian-based systems allow setting default using Debian based alternatives.

$ sudo update-alternatives --set editor /usr/bin/code

Conclusion

We have installed Visual Studio Code in our Ubuntu 22.04 workstation. Go ahead and configure to suite your programming needs. Consult Visual studio code documentation if you face any problem.

How to install Android Studio on Ubuntu 22.04

In this tutorial, we will explore how to install Android Studio on Ubuntu 22.04.

Android Studio is the Integrated Development Environment for Android app development. Whenever you want to start developing android applications, the easiest and the most effective IDE is always the Android studio. It is well tested and offers all the functionalities other code editors provide.

Features of Android Studio

  • It is fast and has many features
  • It offers a unified environment for the development of all android based applications
  • It offers code templates and Github integration for easy code deployment
  • It has extensive testing tools and frameworks.
  • It has linting tools to catch performance, usability, version compatibility
  • It has built-in support for the Google Cloud environment making it easy to integrate the Google App Engine and messaging services

Install Android Studio on Ubuntu 22.04

1. Update system repositories

The first thing is to run system updates so that all the repositories are up to date.

sudo apt update && apt upgrade -y

2. Install required libraries

To begin, we need to install the required libraries. Let’s install those libraries with the following command.

sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386

You will get an output similar to this.

#output
The following additional packages will be installed:
  gcc-12-base:i386 krb5-locales libc6-i386 libcom-err2 libcom-err2:i386
  libcrypt1:i386 libgcc-s1:i386 libgpm2:i386 libgssapi-krb5-2:i386
  libidn2-0:i386 libk5crypto3:i386 libkeyutils1:i386 libkrb5-3:i386
  libkrb5support0:i386 libnsl2:i386 libnss-nis:i386 libnss-nisplus:i386
  libssl3 libssl3:i386 libtinfo5:i386 libtirpc3:i386 libunistring2:i386
Suggested packages:
  glibc-doc:i386 locales:i386 gpm:i386 krb5-doc:i386 krb5-user:i386
The following NEW packages will be installed:
  gcc-12-base:i386 krb5-locales lib32z1 libbz2-1.0:i386 libc6:i386 libc6-i386
  libcom-err2:i386 libcrypt1:i386 libgcc-s1:i386 libgpm2:i386
  libgssapi-krb5-2:i386 libidn2-0:i386 libk5crypto3:i386 libkeyutils1:i386
  libkrb5-3:i386 libkrb5support0:i386 libncurses5:i386 libnsl2:i386
  libnss-nis:i386 libnss-nisplus:i386 libssl3:i386 libstdc++6:i386
  libtinfo5:i386 libtirpc3:i386 libunistring2:i386
The following packages will be upgraded:
  libcom-err2 libssl3
2 upgraded, 25 newly installed, 0 to remove and 182 not upgraded.
Need to get 12.5 MB of archives.
After this operation, 41.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

3. Download Android Studio

Head over to the Android Studio download page and hit on download options to download .gz version for Linux.

sudo wget https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2021.2.1.15/android-studio-2021.2.1.15-linux.tar.gz

After the download is complete, we need to extract the Android Studio

sudo tar -xzvf android-studio-2021.2.1.15-linux.tar.gz

Next, we need to move Android Studio to an appropriate location, for us we are going to move to /opt to enable shared users to use it.

sudo mv android-studio /opt/

3. Launch Android Studio

To start using Android Studio, head over to android-studio/bin/ directory and execute studio.sh

$ cd /opt/android-studio/bin
$ sudo ./studio.sh

When you launch your studio.sh bash command, the configuration wizard will appear.

Select whether you want to import the Android settings or not and then click ok.

nextgentips Android studio welcome page
  • Choose the type of settings you want Android Studio to have. Select standard for now
  • Select the UI theme you want to use.
  • Verify settings that it is ok
  • Accept the license agreement and hit next and finish.

From here the Android Studio will start its installation.

You can now start your project by clicking new project.

4. Uninstall Android Studio

To remove Android studio from your system do the following from the command line.

sudo rm -rf /opt/android-studio/

Conclusion

Congratulations, you have installed Android Studio on Ubuntu 22.04. Happy coding.