Issue installing apache2 in Ubuntu 22.04: dpkg:- error processing package javascript-common (--configure):

When files in a package are modified or accidentally removed, it can damage the system. Installing the package again resolves the problem in most cases. However, using the apt install command will return an error, given that the package is already present.

Here’s the error:

$ sudo apt install apache2

Reading package lists... Done
Building dependency tree       
Reading state information... Done
apache2 is already the newest version.
The following packages were automatically installed and are no longer required:
  libblas3 liblinear-tools liblinear1
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 474 not upgraded.

1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.

Do you want to continue? [Y/n] y
Setting up javascript-common (11) ...
dpkg: error processing package javascript-common (--configure):
 subprocess installed post-installation script returned error exit status 1
 
Errors were encountered while processing:
 javascript-common
E: Sub-process /usr/bin/dpkg returned an error code (1)


The problem might be related to the removal of some critical folders while uninstalling Apache2.

What you need to do is to completely remove the javascript-common and install it back again as follows:

$ sudo apt purge javascript-common 

$ sudo apt install javascript-common


... and then install or reinstall apache2.

$ sudo apt install apache2 

$ sudo apt --reinstall install apache2


That's it __ Hope we could help!!!