I am new to linux, and just beginning to learn bash. I am using Ubuntu 9.04, and would like to add repositories to /etc/apt/sources.list from the command line. Basically, I would like to do this:
sudo echo "[some repository]" >> /etc/apt/sources.list
However, even when I use sudo, I get this error:
bash: /etc/apt/sources.list: Permission denied
How do I avoid this error?
Editing the Ubuntu sources list in the terminal means opening up the /etc/apt/sources. list file in a text-based editor like Nano and manually entering or removing text to disable or enable software repositories.
list. Upfront, the /etc/apt/source. list is a configuration file for Linux's Advance Packaging Tool, that holds URLs and other information for remote repositories from where software packages and applications are installed.
echo "[some repository]" | sudo tee -a /etc/apt/sources.list
The tee command is called as the superuser via sudo and the -a argument tells tee to append to the file instead of overwriting it.
Your original command failed, as the IO redirection with >> will be done as the regular user, only your echo was executed with sudo.
Calling a sudo subshell like
sudo sh -c 'echo "[some repository]" >> /etc/apt/sources.list'
works, too as pointed out by others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With