Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I append text to /etc/apt/sources.list from the command line?

Tags:

bash

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?

like image 515
Matthew Avatar asked May 12 '09 01:05

Matthew


People also ask

How do I edit the source list in Ubuntu?

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.

What is in etc APT sources list?

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.


1 Answers

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.

like image 163
lothar Avatar answered Oct 05 '22 05:10

lothar