Permission denied error running: sudo apt-get update && apt-get install -y [duplicate]

Solution 1:

You forgot to add sudo in the second command so you did not have privileges to run the second command. The install command also did not include the name of a package to install.

The correct syntax for the command you tried to run is:

sudo apt-get update && sudo apt-get install -y packagename

However this command is problematic for a few reasons:

  • When you chain commands with && you do not get to see if the first command was successful or if it needs attention before the second command is executed.

  • When you use the -y option, you ignore confirmation prompts that would let you halt the process if something is not right.

  • sudo apt-get install needs a target package.

It's almost always better to run the commands separately, without the -y option. So one at a time, run:

sudo apt-get update
sudo apt-get install packagename

Replace packagename with the name of the package you are trying to install.

Solution 2:

It is most likely because you aren't using correct syntax when writing the command. Assuming you are trying to install a package and update apt. sudo apt update && sudo apt install <package>. Also, you might want to try to add sudo in front of apt install to run it as root.