How do I add a line to my /etc/apt/sources.list?

  • I am updating my Tor on Ubuntu and it states:

    Do not use the packages in Ubuntu's universe. You'll need to set up our package repository before you can fetch Tor.

    It then states that I have to add this line to your /etc/apt/sources.list file:

     deb <precise> main

    I am uncertain how to add a line to /etc/apt/sources.list.

  • Make a backup copy of your current sources.list file

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

    Append new line of text to current sources.list file

    • CLI

      echo "new line of text" | sudo tee -a /etc/apt/sources.list
    • GUI (Text Editor)

      sudo gedit /etc/apt/sources.list
    • Paste new line of text on new line at end of current sources.list text file in Text Editor.

    • Save and close sources.list

    Don't forget to update in order to use the new repository

    sudo apt-get update
  • In order to add a third-party repository, you first need the public keys for this repository which in this case you can grab from the Ubuntu key server:

    sudo apt-key adv --recv-keys --keyserver 886DDD89

    Now you can add the repository in /etc/apt/sources.list.d/ with add-apt-repository:

    sudo add-apt-repository "deb $(lsb_release -s -c) main"

    After adding any repository it is always needed to execute

    sudo apt-get update

    Now you can install the package for Tor itself. For complete instructions on how to install Tor correctly, see How to install Tor?

    This procedure can also be reversed.

    +1, do not use `/etc/apt/sources.list` for third-party repos, use `/etc/apt/sources.list.d/` instead.

    @hudolejev how do you specify a file in the `/etc/apt/sources.list.d/` using the command `add-apt-repository`? From the man page I can not figure it out it seems like it happens magically, however when using that command I keep seeing lines added to the file `/etc/apt/sources.list` instead

    @TPPZ my previous comment is 6 years old, I don't quite remember the context. Maybe it was and answer to some other comment that is now deleted :/ Anyways, seems that `add-apt-repository` will only create separate files in `sources.list.d` for PPA repos, for others it will update `sources.list`:

  • Easiest way on Ubuntu:

    Go to Ubuntu Software Centre > Edit > Software Sources > Add

    Paste the line from the Tor website into the APT line box.

    You could also manually edit /etc/apt/sources.list, but probably simplest to go through the Software Centre.

    Make sure to input the line correctly as well, e.g.

    deb precise main

    if you're using 12.04. If something goes wrong edit /etc/apt/sources.list to fix it.

  • First, make a backup. You can do so with:

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

    in the Terminal. Give your password and press Enter. It will not be shown, not even asterisks. Then run:

    gksudo gedit /etc/apt/sources.list

    and give your password.

    Add the line:

     deb main

    to the bottom of the file and use File->Save to save it.

    Then, go back to the terminal and run:

    sudo apt-get update

    and then continue following the instructions. This command and the one starting in sudo apt-get install may take a while. Additionally, the install command may give a:

    Do you want to continue[y/n]?

    prompt, where you must type y and press Enter to continue.

  • You need not to edit default /etc/apt/sources.list, you better upgrade your Ubuntu to Saucy. Here Tor is in the official repository.

    See, my /etc/apt/sources.list:

    deb saucy main restricted universe multiverse
    deb saucy-updates main restricted universe multiverse
    deb saucy-backports main restricted universe multiverse
    deb saucy-security main restricted universe multiverse

    Only 4 lines.

    I'm able to download and install the Tor package:

    # aptitude download tor
    Get: 1 saucy/universe tor amd64 [953 kB]
    84% [1 tor 799 kB/953 kB 84%]201 URI Done:
    RecivedHash: MD5Sum:1cb3ed029c169c3a5e528dd7d28cc60f
    ExpectedHash: MD5Sum:1cb3ed029c169c3a5e528dd7d28cc60f
    Fetched 953 kB in 4s (198 kB/s)

    According to Tor on Linux, one of the common installations.

  • Basically sources.list is a text file you want to edit. Linux is all about file you can customize your ubuntu by changing files. so the basic way to edit files(adding or deleting text) is by using some of the text editor like:

    • emacs,gedit(gui based)
    • nano,vi,vim(cli based)

    You can install them by typing sudo apt-get install text_editor_name.

    type man text_editor_name for reading their mannual pages.

    • If the status is you don't hav permissions, use:

      chmod 777 filename

    why don't you just use sudo and not changing the permissions?

  • Check this video link and see how to fix the problem

    Using Terminal text editor program 'nano' we can edit the file '/etc/apt/sources.list' .

    Open terminal and type:

    ' sudo nano /etc/apt/sources.list '

    After making necessary changes, use the keyboard combination 'ctrl + o' and after that press 'Enter' to save the file to its current location.

    Use the keyboard combination 'ctrl + x' to exit nano.

    Please include the essential parts of the answer here (list what all "necessary changes" have to be made).

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM