4

I'm creating some scripts to streamline application installations and I need to append to the end of /etc/apt/sources.list

This code below append to files in ~ but not in /etc/apt/

echo "deb http://ppa.launchpad.net/person/ppa/ubuntu karmic main" >> /etc/apt/sources.list

@meder

I have tried these following commands with no luck:

sudo echo "deb http://ppa.launchpad.net/person/ppa/ubuntu karmic main" >> /etc/apt/sources.list
#===---
sudo sh "echo 'deb http://ppa.launchpad.net/person/ppa/ubuntu karmic main' >> /etc/apt/sources.list"
Jonathan Leffler
  • 698,132
  • 130
  • 858
  • 1,229
RyanScottLewis
  • 12,386
  • 14
  • 53
  • 83

2 Answers2

24

This will work:

sudo sh -c "echo 'deb http://ppa.launchpad.net/person/ppa/ubuntu karmic main' >> /etc/apt/sources.list"

However, instead of editing /etc/apt/sources.list, it is simpler to add a new *.list file to /etc/apt/sources.list.d.

For example,

echo 'deb http://ppa.launchpad.net/person/ppa/ubuntu karmic main' >/tmp/myppa.list
sudo cp /tmp/myppa.list /etc/apt/sources.list.d/
rm /tmp/myppa.list
ephemient
  • 189,938
  • 36
  • 271
  • 385
  • 4
    FYI: whoever edited the `sudo cp + rm` to a `mv`: don't do that. The reason for `cp` is to use root's permissions, whereas with `mv` the file will end up with the current user's permissions. – ephemient Jan 24 '17 at 20:47
3

make sure to have a backup file

echo "foo" | sudo tee -a /etc/apt/sources.list

However, I would really recommend you create a new .list and then use this method to append, store it in /etc/apt/sources.list.d/

meder omuraliev
  • 177,923
  • 69
  • 381
  • 426