Cyberithub

How to Install Screen command on Ubuntu 22.04

Advertisements

In this article, we will see how to install screen command on Ubuntu 22.04. If you are looking to create and manage multiple tasks with remote server on a single interface then screen would be the ideal utility to use. You can easily detach the long running processes from your terminal to make sure it does not terminate due to some network or other local issues. Even if you are logged out from remote server, your task would continue to run till it finishes.

You can also reattach the detached session from same or different terminal session. screen is a free and open source utility which can be easily installed on Linux or Unix based systems. Here we will see the steps to install screen command on Ubuntu 22.04 based systems.

 

How to Install Screen command on Ubuntu 22.04

How to Install Screen command on Ubuntu 22.04

Also Read: How to kill all detached screen sessions on Linux or Unix

Step 1: Prerequisites

a) You should have a running Ubuntu 22.04 Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get utility available in your server.

d) Minimum hardware requirements:-

  • CPU: Any latest or even older CPU should be enough.
  • RAM: Memory from 512 MB to 1 GB should be enough.

 

Step 2: Update Your Server

Before installing screen packages, run below command to check and install all the latest available upgrades from default Ubuntu repo. This will help install all the latest security patches and bugfixes.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade

 

Step 3: Install Screen command

Then to install screen utility, run sudo apt install screen command as shown below. This command allows you to install screen package from default Ubuntu repo along with all its required dependencies.

cyberithub@ubuntu:~$ sudo apt install screen
[sudo] password for cyberithub:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libutempter0
Suggested packages:
byobu | screenie | iselect
The following NEW packages will be installed:
libutempter0 screen
0 upgraded, 2 newly installed, 0 to remove and 66 not upgraded.
Need to get 680 kB of archives.
After this operation, 1,081 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 libutempter0 amd64 1.2.1-2build2 [8,848 B]
Get:2 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 screen amd64 4.9.0-1 [672 kB]
Fetched 680 kB in 2s (324 kB/s)
Selecting previously unselected package libutempter0:amd64.
(Reading database ... 244813 files and directories currently installed.)
Preparing to unpack .../libutempter0_1.2.1-2build2_amd64.deb ...
Unpacking libutempter0:amd64 (1.2.1-2build2) ...
Selecting previously unselected package screen.
Preparing to unpack .../screen_4.9.0-1_amd64.deb ...
Unpacking screen (4.9.0-1) ...
Setting up libutempter0:amd64 (1.2.1-2build2) ...
Setting up screen (4.9.0-1) ...
Processing triggers for install-info (6.8-4build1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.6) ...
Processing triggers for man-db (2.10.2-1) ...

 

Step 4: Verify Installation

To verify package installation status, run dpkg -s screen command as you can see below. To know more about dpkg command, check 21+ Practical dpkg Command Examples for Linux Beginners.

cyberithub@ubuntu:~$ dpkg -s screen
Package: screen
Status: install ok installed
Priority: standard
Section: misc
Installed-Size: 1005
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 4.9.0-1
Depends: libc6 (>= 2.34), libcrypt1 (>= 1:4.1.0), libpam0g (>= 0.99.7.1), libtinfo6 (>= 6), libutempter0 (>= 1.1.5)
Suggests: byobu | screenie | iselect (>= 1.4.0-1), ncurses-term
Conffiles:
 /etc/init.d/screen-cleanup 44ec7824f5ef10df73e92ad064331ea0
 /etc/screenrc 12c245238eb8b653625bba27dc81df6a
............................................

From above output, you can get below information:-

  • Package Name: The name of the package (screen in this case).
  • Status: This indicates whether the package is installed, not installed, or marked for installation or removal.
  • Version: The version of the package that is currently installed.
  • Dependencies: Lists other packages that screen depends on to function properly.
  • Description: A brief description of what the screen package does.
  • Maintainer: The contact information for the person or team responsible for maintaining the package.

 

Step 5: Check Version

To only check the current installed version of screen utility, run screen --version command as shown below.

cyberithub@ubuntu:~$ screen --version
Screen version 4.09.00 (GNU) 30-Jan-22

 

Step 6: Launch Screen session

Now that screen utility is installed, you can launch a screen detached session by using screen -d -m top command as shown below. Here -d option is used for detaching the screen session from terminal interface and allow it to run on background and -m option is used to force create a new screen session.

cyberithub@ubuntu:~$ screen -d -m top

To check the launched detached session, run screen -ls command.

cyberithub@ubuntu:~$ screen -ls
There is a screen on:
17261..ubuntu (24/03/24 03:08:55 AM IST) (Detached)
1 Socket in /run/screen/S-cyberithub.

 

Step 7: Reattach a screen session

You can also choose to reattach a detached screen session. For example, here we are reattaching session 17261 using screen -r 17261 command as shown below. Here -r option is used to reattach the detached session.

cyberithub@ubuntu:~$ screen -r 17261
top - 03:10:43 up 2:37, 3 users, load average: 0.07, 0.02, 0.00
Tasks: 179 total, 1 running, 178 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 1959.2 total, 231.1 free, 386.8 used, 1341.3 buff/cache
MiB Swap: 6044.0 total, 5592.7 free, 451.3 used. 1394.5 avail Mem

PID   USER     PR NI VIRT    RES    SHR    S %CPU %MEM TIME+   COMMAND
2689  cyberit+ 20 0  3489944 176652 118672 S 0.3  8.8  0:36.05 gnome-shell
17262 cyberit+ 20 0  13228   4224   3456   R 0.3  0.2  0:00.16 top
1     root     20 0  168308  13020  7900   S 0.0  0.6  0:04.22 systemd
2     root     20 0  0       0      0      S 0.0  0.0  0:00.00 kthreadd
.....................................

 

Step 8: Kill a Session

If you are looking to kill a screen session without reattaching it then you can use screen -S <session id/name> -X quit command. Here -S option is used to specify the screen session id or name and -X option is used to send a specific command to that session, in our case quit command to session 17274. This method allows to kill a session without the need of reattaching it.

cyberithub@ubuntu:~$ screen -S 17274 -X quit

To verify, run screen -ls command. You won't see that session running.

cyberithub@ubuntu:~$ screen -ls
No Sockets found in /run/screen/S-cyberithub.

 

Step 9: Check all available options

To check all the options available with screen command, run screen --help command as shown below.

cyberithub@ubuntu:~$ screen --help

 

Step 10: Uninstall Screen command

If you don't need screen utility anymore then you can very well remove it from your system by using sudo apt remove screen command as shown below. To remove all dependent packages, use --auto-remove option with below command.

cyberithub@ubuntu:~$ sudo apt remove screen
[sudo] password for cyberithub:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
libutempter0
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
screen
0 upgraded, 0 newly installed, 1 to remove and 66 not upgraded.
After this operation, 1,029 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 244880 files and directories currently installed.)
Removing screen (4.9.0-1) ...
Processing triggers for install-info (6.8-4build1) ...
Processing triggers for man-db (2.10.2-1) ...

Leave a Comment