You are running the cat
command as root, but the output redirection takes place in your current shell which runs as your normal user account.
You have at least three options to achieve your goal of adding lines to your apt
sources:
Running the whole command including output redirection in a separate Bash root shell:
sudo bash -c 'cat >> /etc/apt/sources.list'
Using the tee
command that copies output to a file (-a
option to append to instead of overwrite existing files) and running that as root:
cat | sudo tee -a /etc/apt/sources.list
Using a terminal editor application like nano
as root to modify the file:
sudo nano /etc/apt/sources.list
However, it is recommended to leave your /etc/apt/sources.list
file as it is and add additional sources by creating new *.list
files inside /etc/apt/sources.list.d/
.
sudo
applies only to the command (cat
) not to opening the file via the redirection operator. To append to the restricted file, you need to elevate privilege on the file operation, not thecat
, for example,echo "# foo" | sudo tee -a /etc/apt/sources.list
– user4556274 Sep 28 '16 at 14:23