chmod 0644 :Operation not permitted - ubuntu-18.04

i wanted to download java using sudo apt on ubuntu 18.04 but it sent me "E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"
so i tried to run "apt-get update" which sent me lots of error that looks like this " chmod 0644 of file /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_bionic_InRelease failed - 201::URIDone (1: Operation not permitted)" so i tried to change the permission using chmod 0644 /var/lib/apt/lists/"
but it didn't work also tried a couple other methods but still didn't work
so hopefully you can tell me what to try to fix it.
btw i'm using windows 10 and running ubuntu 18.04 from the windows store

Remove those files sudo rm -r /var/lib/apt/lists/* and rerun sudo apt-get update

Related

opam init fails to verify certificate

On a completely fresh ubuntu 18.04 VM I tried to install opam:
$ wget https://github.com/ocaml/opam/releases/download/2.1.0/opam-2.1.0-x86_64-linux
$ mv opam-2.1.0-x86_64-linux opam
$ chmod 777 opam
$ ./opam init
And here is the error I got
<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><><><>
[ERROR] Could not update repository "default": OpamDownload.Download_fail(_,
"Download command failed: \"/usr/bin/wget --content-disposition -t 3 -O
/tmp/opam-5936-f23d09/index.tar.gz.part -U opam/2.1.0 --
https://opam.ocaml.org/index.tar.gz\" exited with code 5 \"ERROR:
cannot verify opam.ocaml.org's certificate, issued by
\226\128\152CN=Zscaler Intermediate Root CA (zscaler.net) (t)\\\\
,OU=Zscaler Inc.,O=Zscaler Inc.,ST=California,C=US\226\128\153:\"")
[ERROR] Initial download of repository failed.
How should I solve this?
I ran into the same issue and I found a workaround on the OCaml forum: here. (Credits to UnixJunkie)
You can run:
opam init github git+https://github.com/ocaml/opam-repository.git
This should avoid the certificate issues. This worked for me.
I tried to fix the certificate issues using this answer as well. You could try doing that, but it seems complicated when the workaround is to simply point it to the github repo directly.
Update
The reason opam init failed for me was because curl was installed with snap on my system.
Try to run opam init -verbose and that could reveal more about why you ran into an error.
In my case I needed to install other things with opam and it kept failing every time. So snap uninstall curl and then sudo apt install curl fixed things. (Was only able to figure this out with the help from my professor)

dpkg can't install pgAdmin4-web on my debian

I tried installing pgadmin4 on debian10 and it reported:
dpkg: error processing archive /var/cache/apt/archives/pgadmin4-web_4.24_all.deb (--unpack):
trying to overwrite '/etc/apache2/conf-available/pgadmin4.conf', which is also in package pgadmin4-apache2 4.23-1.pgdg100+1
Try force-overwriting :
sudo dpkg -i --force-overwrite /var/cache/apt/archives/pgadmin4-web_4.24_all.deb
sudo apt-get -f install
I just want to extend the answer of Thirumal. Just
try to get into
cd /var/cache/apt/archives/
You will find the exact version of your pgadmin4-web there.The version at the time of writing this answer is
pgadmin4-web_4.28_all.deb
After you locate your own version then apply the following two commands
sudo dpkg -i --force-overwrite /var/cache/apt/archives/pgadmin4-web_YOUR VERSION_all.deb
sudo apt-get -f install

Cannot upgrade from Ubuntu 18.10 to 19.10

When running the command sudo do-release upgrade I'm facing the following errors:
Checking package manager
Can not upgrade
An upgrade from 'cosmic' to 'eoan' is not supported with this tool.
Since 18.10 no longer supported you can upgrade manually to 19.04
mkdir /tmp/upgrade
cd /tmp/upgrade
wget http://old-releases.ubuntu.com/ubuntu/dists/disco-updates/main/dist-upgrader-all/current/disco.tar.gz
tar -xvf disco.tar.gz
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
/etc/apt/sources.list change all links prefix to -> http://old-releases.ubuntu.com/
sudo python3 dist-upgrade.py
Then upgrade to 19.10
sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
sudo sed -i -e 's|cosmic|eoan|g' /etc/apt/sources.list
sudo apt update
sudo apt upgrade
I just experienced the whole process of upgrading from 18.10 to 20.04LTS. Key steps are first upgrading from 18.10(cosmic) to 19.04(disco), then 19.10(eoan), finally 20.04LTS(focal).
Upgrade from 18.10 to 19.04. First, we have to manually download disco updates:
mkdir /tmp/upgrade
cd /tmp/upgrade
wget http://old-releases.ubuntu.com/ubuntu/dists/disco-updates/main/dist-upgrader-all/current/disco.tar.gz
tar -xf disco.tar.gz
Now, modify /etc/apt/sources.list(Tip: you'd better save the original sources.list as a backup). This file in Ubuntu 18.10 is like this:
However, "archive.ubuntu.com" has been dead, so we have to replace these links by "old-releases.ubuntu.com", then run dist-upgrade.py in current directory, which is extracted from disco.tar.gz:
sudo sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
sudo sed -i 's/cosmic/disco/g' /etc/apt/sources.list # some answers may forget this
sudo python3 dist-upgrade.py
Note that if you forget to replace "cosmic" with "disco", when running this script, it may throw this dialogue box:
Don't worry, choose "Yes", just like it said, it will update all "cosmic" to "disco" entries.
When this script succeeds, reboot your system and now you have Ubuntu 19.04(disco). Your /etc/apt/sources.list should be like this:
Upgrade from 19.04 to 19.10. Again, replace "disco" to "eoan" in /etc/apt/sources.list. Now you can run apt for updating:
sudo sed -i 's/cosmic/eoan/g' /etc/apt/sources.list
sudo apt update
sudo apt upgrade
If everything goes well, reboot your system and you got 19.10(eoan)! If you just want 19.10, feel free to skip step 3, it's for users who want 20.04 LTS.
Upgrade from 19.10 to 20.04 LTS. This is quite easy, just use Ubuntu Software Updater, it will do everything for you. It took me about 2-3 hours to download and install all updates.

PostgreSQL installation failed on Ubuntu 14.04

I recently uninstalled postgresql from my computer. I tried to install it again but I faced some problems. I tried to fully uninstall it again like this:
I found al the packages related to postgres:
$ dpkg -l | grep postgres
Them I removed all the packages and related folders :
$ sudo apt-get --purge remove postgresql postgresql-9.3 postgresql-client-9.3 postgresql-client-common postgresql-common postgresql-contrib-9.3
$ sudo rm -rf /var/lib/postgresql/
$ sudo rm -rf /var/log/postgresql/
$ sudo rm -rf /etc/postgresql/
I've tried to install it again, but after the installation I can't access postgres user.
$ sudo apt-get install postgresql postgresql-contrib
$ sudo -i -u postgres
sudo: unable to change directory to /home/postgres: No such file or directory
If I access root I can access postgres but this is what happens:
$ sudo su -
$ su - postgres
No directory, logging in with HOME=/
postgres#rafael-pc:/$ psql
psql (9.3.9)
Type "help" for help.
postgres=# \q
could not save history to file "/home/postgres/.psql_history": No such file or directory
I have no idea what is happening. I've tried to uninstall it many times but I always have some kind of error when I install it back.
Just a guess here, but it sure looks to me like the problem is that there isn't a /home/postgres directory. I'm not sure what may have happened in your uninstall process to remove that, but it looks like that's the cause of the error in both of the steps you list.
Can you try this (or some approximation of these steps, which create that directory and make sure it's owned by the postgres user)?
# sudo mkdir /home/postgres
# sudo chown postgres /home/postgres

Executing commands in a series in ubuntu terminal

Suppose I have a set of commands to be executed in ubuntu terminal:
for eg:
sudo apt-get update
sudo install xrdp
sudo install java
.....
and many others.
Is it possible in ubuntu to execute the file containing these commands and execute without human intervention (like yes/no) , by default yes?
I tried installing wine , executing $wine cmd /c Commands.bat , after putting all these commands in .bat file but getting errors "Application tried to create a window, but no driver could be loaded."
So, is there any simple way of executing a series of commands in ubuntu?
What you are talking about - multiple commands in one file - is called a "shellscript".
Let's say you have commands.sh:
sudo apt-get update
sudo install xrdp
sudo install java
Then you could execute the commands using:
bash commands.sh
You can also make a directly executable shellscript out of it using the so called shebang mechanism.
Put this line on the very top (line 1) of commands.sh
#!/bin/bash
.. and make the file executable:
chmod +x commands.sh
Now you can execute it directly:
./commands.sh
If you want to say "yes" to all questions, you can use the yes command:
yes | bash "file_with_commands.sh"
No need to do something convolutied and as insane as trying to make cmd.exe work. You already got a perfectly fine working shell on your system. Also you need to understand what programs like sudo do.
sudo is not some magic chant that enables something. sudo is a helper program that allows to start a program with elevated rights. Instead of having a chain of sudo this sudo that you can as just let sudo start a shell and pass a script with all those commands to the shell.
Turning
sudo apt-get update
sudo install xrdp
sudo install java
Into
sudo sh -c 'apt-get update ; install xrdp ; install java'
However that doesn't look right. I think you originally meant to write
sudo apt-get update
sudo apt-get install xrdp
sudo apt-get install java
You can shorten this to
sudo apt-get update
sudo apt-get install xrdp java
Or in coalesced single liner shell
sudo sh -c 'apt-get update ; apt-get install xrdp java'
Now regarding the Yes/No questions. If a program you want to run unattended doesn't offer an option to give a default answer you can make use of the yes program. Even it being named yes it can also answer NO or anything you like:
narfi /home/dw
1007 ~ % yes Hello
Hello
Hello
Hello
Hello
Hello
…
How does this work? There's a concept called the "Standard Input / Output" from which programs read input from and write output to. Shells allow you to redirect the output from one program into the input of another one. This is called pipe-ing. The special character | designates a pipe in shells.
So say you've got a program that wants to see a large number of Aye inputs you could make the following call to the shell
yes Aye | happypirate
So you can combine this with apt-get to give all default yes answer writing
yes | apt-get install …
However this is barking up the wrong tree. Have a look at the call options for apt-get:
~ % apt-get --help
apt 0.9.7.6 for amd64 compiled on Oct 16 2012 18:23:06
Usage: apt-get [options] command
apt-get [options] install|remove pkg1 [pkg2 ...]
apt-get [options] source pkg1 [pkg2 ...]
apt-get is a simple command line interface for downloading and
installing packages. The most frequently used commands are update
and install.
…
-y Assume Yes to all queries and do not prompt <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
…
apt-get gives you an option to auto-answer all yes to all it questions. Neat, right? Note that other programs may use different option keys so you're well advised to always read their fine manuals (RTFM).
At its most basic level, you want to eecute a script. You do that by creating a file like this:
#!/bin/bash
sudo apt-get update
sudo install xrdp
sudo install java
Save that as a file called go, then in the Terminal, you need to make it executable like this:
chmod +x go
Then you can run it by typing:
./go
If your program expects an answer of "yes" for the first question, then "no" for the next question, you can prepare the answers in advance like this and send them into the program:
( echo yes; echo no ) | sudo apt-get update

Resources