How to edit sources.list as root under Debian 9?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















So I just installed Debian 9.0.0 on my PC and now I can't download packages with the Synaptic packet manager as the sources.list file under /etc/apt/ has only the DVD set.



All other lines are commented out, with this text above the 2 lines I'd like to take back in:



# Line commented out by installer because it failed to verify:


This is probably due to the fact that I wasn't connected to the Internet while installing Debian using the DVD.



Also apparently the DVD isn't detected under Debian as under /media/ it only says cdrom and cdrom0 no matter if I insert the DVD or not with both being empty. -> Not sure if that is a separate issue?



I cannot edit the sources.list file by just opening it with the texteditor as it's write-protected.

I thought about installing leafpad from here: https://packages.debian.org/stretch/amd64/leafpad/download and I'm not sure if that would help.



To me it seems that the most straight-forward way would be to open the texteditor as root, comment out the DVD sources and take the 2 security.debian.org sources back in. However I'm not sure how to do that.



I tried sudo gedit which gets me this (I translated the part after Unable to init server:):



No protocol specified
Unable to init server: Connection failed:connection buildup denied

(gedit:1297): Gtk-WARNING **: cannot open display: :0


I would greatly appreciate any help.










share|improve this question






















  • What about opening a console and using su - to become root? If that fails, what about changing to a fully black screen with CTRL-ALT-F2 (get back to the graphical interface with CTRL-ALT-F7) and login as root and the root password. Failing that, better just reinstall, other procedures are too complex to explain in a comment.

    – Arrow
    Jun 23 '17 at 1:22











  • @Arrow “better just reinstall, other procedures are too complex to explain in a comment” — so write an answer then... Note that on current Debian, the GUI is typically on VT2 so Ctrl-Alt-F2 isn’t going to do much.

    – Stephen Kitt
    Jun 23 '17 at 4:33











  • About writing an answer: there is no point as the user has moved to other questions, as you suggested.

    – Arrow
    Jun 23 '17 at 4:47






  • 1





    because I am shooting in the dark here not knowing the answer to all the above. That is not a problem but we need to work one step at the time. First, you said that su - worked, then, in that console whoami should say root, or id should report you are root. If so, edit any file with nano, like nano /etc/apt/sources.list. Second question, in a nrmal console (not root) could you execute sudo ls. If not, you need to edit sudoers. Then, after sudoers is correct, could you start a gui command like sudo xterm ?. If not we need to make xauthority of the running user available (cont.)

    – Arrow
    Jun 23 '17 at 10:58






  • 1





    @mYnDstrEAm You could start xterm (as root?). So, you do have a password for root and you have edited sudo to accept your user. Fine, anything else we should take a look to to repair here?

    – Arrow
    Jun 23 '17 at 19:07
















0















So I just installed Debian 9.0.0 on my PC and now I can't download packages with the Synaptic packet manager as the sources.list file under /etc/apt/ has only the DVD set.



All other lines are commented out, with this text above the 2 lines I'd like to take back in:



# Line commented out by installer because it failed to verify:


This is probably due to the fact that I wasn't connected to the Internet while installing Debian using the DVD.



Also apparently the DVD isn't detected under Debian as under /media/ it only says cdrom and cdrom0 no matter if I insert the DVD or not with both being empty. -> Not sure if that is a separate issue?



I cannot edit the sources.list file by just opening it with the texteditor as it's write-protected.

I thought about installing leafpad from here: https://packages.debian.org/stretch/amd64/leafpad/download and I'm not sure if that would help.



To me it seems that the most straight-forward way would be to open the texteditor as root, comment out the DVD sources and take the 2 security.debian.org sources back in. However I'm not sure how to do that.



I tried sudo gedit which gets me this (I translated the part after Unable to init server:):



No protocol specified
Unable to init server: Connection failed:connection buildup denied

(gedit:1297): Gtk-WARNING **: cannot open display: :0


I would greatly appreciate any help.










share|improve this question






















  • What about opening a console and using su - to become root? If that fails, what about changing to a fully black screen with CTRL-ALT-F2 (get back to the graphical interface with CTRL-ALT-F7) and login as root and the root password. Failing that, better just reinstall, other procedures are too complex to explain in a comment.

    – Arrow
    Jun 23 '17 at 1:22











  • @Arrow “better just reinstall, other procedures are too complex to explain in a comment” — so write an answer then... Note that on current Debian, the GUI is typically on VT2 so Ctrl-Alt-F2 isn’t going to do much.

    – Stephen Kitt
    Jun 23 '17 at 4:33











  • About writing an answer: there is no point as the user has moved to other questions, as you suggested.

    – Arrow
    Jun 23 '17 at 4:47






  • 1





    because I am shooting in the dark here not knowing the answer to all the above. That is not a problem but we need to work one step at the time. First, you said that su - worked, then, in that console whoami should say root, or id should report you are root. If so, edit any file with nano, like nano /etc/apt/sources.list. Second question, in a nrmal console (not root) could you execute sudo ls. If not, you need to edit sudoers. Then, after sudoers is correct, could you start a gui command like sudo xterm ?. If not we need to make xauthority of the running user available (cont.)

    – Arrow
    Jun 23 '17 at 10:58






  • 1





    @mYnDstrEAm You could start xterm (as root?). So, you do have a password for root and you have edited sudo to accept your user. Fine, anything else we should take a look to to repair here?

    – Arrow
    Jun 23 '17 at 19:07














0












0








0








So I just installed Debian 9.0.0 on my PC and now I can't download packages with the Synaptic packet manager as the sources.list file under /etc/apt/ has only the DVD set.



All other lines are commented out, with this text above the 2 lines I'd like to take back in:



# Line commented out by installer because it failed to verify:


This is probably due to the fact that I wasn't connected to the Internet while installing Debian using the DVD.



Also apparently the DVD isn't detected under Debian as under /media/ it only says cdrom and cdrom0 no matter if I insert the DVD or not with both being empty. -> Not sure if that is a separate issue?



I cannot edit the sources.list file by just opening it with the texteditor as it's write-protected.

I thought about installing leafpad from here: https://packages.debian.org/stretch/amd64/leafpad/download and I'm not sure if that would help.



To me it seems that the most straight-forward way would be to open the texteditor as root, comment out the DVD sources and take the 2 security.debian.org sources back in. However I'm not sure how to do that.



I tried sudo gedit which gets me this (I translated the part after Unable to init server:):



No protocol specified
Unable to init server: Connection failed:connection buildup denied

(gedit:1297): Gtk-WARNING **: cannot open display: :0


I would greatly appreciate any help.










share|improve this question














So I just installed Debian 9.0.0 on my PC and now I can't download packages with the Synaptic packet manager as the sources.list file under /etc/apt/ has only the DVD set.



All other lines are commented out, with this text above the 2 lines I'd like to take back in:



# Line commented out by installer because it failed to verify:


This is probably due to the fact that I wasn't connected to the Internet while installing Debian using the DVD.



Also apparently the DVD isn't detected under Debian as under /media/ it only says cdrom and cdrom0 no matter if I insert the DVD or not with both being empty. -> Not sure if that is a separate issue?



I cannot edit the sources.list file by just opening it with the texteditor as it's write-protected.

I thought about installing leafpad from here: https://packages.debian.org/stretch/amd64/leafpad/download and I'm not sure if that would help.



To me it seems that the most straight-forward way would be to open the texteditor as root, comment out the DVD sources and take the 2 security.debian.org sources back in. However I'm not sure how to do that.



I tried sudo gedit which gets me this (I translated the part after Unable to init server:):



No protocol specified
Unable to init server: Connection failed:connection buildup denied

(gedit:1297): Gtk-WARNING **: cannot open display: :0


I would greatly appreciate any help.







debian software-installation root






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 22 '17 at 15:20









mYnDstrEAmmYnDstrEAm

79151445




79151445












  • What about opening a console and using su - to become root? If that fails, what about changing to a fully black screen with CTRL-ALT-F2 (get back to the graphical interface with CTRL-ALT-F7) and login as root and the root password. Failing that, better just reinstall, other procedures are too complex to explain in a comment.

    – Arrow
    Jun 23 '17 at 1:22











  • @Arrow “better just reinstall, other procedures are too complex to explain in a comment” — so write an answer then... Note that on current Debian, the GUI is typically on VT2 so Ctrl-Alt-F2 isn’t going to do much.

    – Stephen Kitt
    Jun 23 '17 at 4:33











  • About writing an answer: there is no point as the user has moved to other questions, as you suggested.

    – Arrow
    Jun 23 '17 at 4:47






  • 1





    because I am shooting in the dark here not knowing the answer to all the above. That is not a problem but we need to work one step at the time. First, you said that su - worked, then, in that console whoami should say root, or id should report you are root. If so, edit any file with nano, like nano /etc/apt/sources.list. Second question, in a nrmal console (not root) could you execute sudo ls. If not, you need to edit sudoers. Then, after sudoers is correct, could you start a gui command like sudo xterm ?. If not we need to make xauthority of the running user available (cont.)

    – Arrow
    Jun 23 '17 at 10:58






  • 1





    @mYnDstrEAm You could start xterm (as root?). So, you do have a password for root and you have edited sudo to accept your user. Fine, anything else we should take a look to to repair here?

    – Arrow
    Jun 23 '17 at 19:07


















  • What about opening a console and using su - to become root? If that fails, what about changing to a fully black screen with CTRL-ALT-F2 (get back to the graphical interface with CTRL-ALT-F7) and login as root and the root password. Failing that, better just reinstall, other procedures are too complex to explain in a comment.

    – Arrow
    Jun 23 '17 at 1:22











  • @Arrow “better just reinstall, other procedures are too complex to explain in a comment” — so write an answer then... Note that on current Debian, the GUI is typically on VT2 so Ctrl-Alt-F2 isn’t going to do much.

    – Stephen Kitt
    Jun 23 '17 at 4:33











  • About writing an answer: there is no point as the user has moved to other questions, as you suggested.

    – Arrow
    Jun 23 '17 at 4:47






  • 1





    because I am shooting in the dark here not knowing the answer to all the above. That is not a problem but we need to work one step at the time. First, you said that su - worked, then, in that console whoami should say root, or id should report you are root. If so, edit any file with nano, like nano /etc/apt/sources.list. Second question, in a nrmal console (not root) could you execute sudo ls. If not, you need to edit sudoers. Then, after sudoers is correct, could you start a gui command like sudo xterm ?. If not we need to make xauthority of the running user available (cont.)

    – Arrow
    Jun 23 '17 at 10:58






  • 1





    @mYnDstrEAm You could start xterm (as root?). So, you do have a password for root and you have edited sudo to accept your user. Fine, anything else we should take a look to to repair here?

    – Arrow
    Jun 23 '17 at 19:07

















What about opening a console and using su - to become root? If that fails, what about changing to a fully black screen with CTRL-ALT-F2 (get back to the graphical interface with CTRL-ALT-F7) and login as root and the root password. Failing that, better just reinstall, other procedures are too complex to explain in a comment.

– Arrow
Jun 23 '17 at 1:22





What about opening a console and using su - to become root? If that fails, what about changing to a fully black screen with CTRL-ALT-F2 (get back to the graphical interface with CTRL-ALT-F7) and login as root and the root password. Failing that, better just reinstall, other procedures are too complex to explain in a comment.

– Arrow
Jun 23 '17 at 1:22













@Arrow “better just reinstall, other procedures are too complex to explain in a comment” — so write an answer then... Note that on current Debian, the GUI is typically on VT2 so Ctrl-Alt-F2 isn’t going to do much.

– Stephen Kitt
Jun 23 '17 at 4:33





@Arrow “better just reinstall, other procedures are too complex to explain in a comment” — so write an answer then... Note that on current Debian, the GUI is typically on VT2 so Ctrl-Alt-F2 isn’t going to do much.

– Stephen Kitt
Jun 23 '17 at 4:33













About writing an answer: there is no point as the user has moved to other questions, as you suggested.

– Arrow
Jun 23 '17 at 4:47





About writing an answer: there is no point as the user has moved to other questions, as you suggested.

– Arrow
Jun 23 '17 at 4:47




1




1





because I am shooting in the dark here not knowing the answer to all the above. That is not a problem but we need to work one step at the time. First, you said that su - worked, then, in that console whoami should say root, or id should report you are root. If so, edit any file with nano, like nano /etc/apt/sources.list. Second question, in a nrmal console (not root) could you execute sudo ls. If not, you need to edit sudoers. Then, after sudoers is correct, could you start a gui command like sudo xterm ?. If not we need to make xauthority of the running user available (cont.)

– Arrow
Jun 23 '17 at 10:58





because I am shooting in the dark here not knowing the answer to all the above. That is not a problem but we need to work one step at the time. First, you said that su - worked, then, in that console whoami should say root, or id should report you are root. If so, edit any file with nano, like nano /etc/apt/sources.list. Second question, in a nrmal console (not root) could you execute sudo ls. If not, you need to edit sudoers. Then, after sudoers is correct, could you start a gui command like sudo xterm ?. If not we need to make xauthority of the running user available (cont.)

– Arrow
Jun 23 '17 at 10:58




1




1





@mYnDstrEAm You could start xterm (as root?). So, you do have a password for root and you have edited sudo to accept your user. Fine, anything else we should take a look to to repair here?

– Arrow
Jun 23 '17 at 19:07






@mYnDstrEAm You could start xterm (as root?). So, you do have a password for root and you have edited sudo to accept your user. Fine, anything else we should take a look to to repair here?

– Arrow
Jun 23 '17 at 19:07











2 Answers
2






active

oldest

votes


















1














Since you have sudo working, you should use sudoedit:



SUDO_EDITOR="gedit -w" sudoedit /etc/apt/sources.list





share|improve this answer

























  • That only works as 2 separate commands. sudoedit /etc/apt/sources.list almost worked - I tried to save it with ctrl+o (it confusingly only said ^O) but then it asks me for the filename with only strange options instead of an option to replace the original file. How can I replace it? Furthermore I can't open the root console anymore - the screen only flickers black after I enter the password.

    – mYnDstrEAm
    Jun 22 '17 at 15:32











  • Let us continue this discussion in chat.

    – Arrow
    Jun 23 '17 at 4:50











  • Seriously, it’s a single command. If you want to make it two, first you need to export SUDO_EDITOR="gedit -w", then sudoedit /etc/apt/sources.list.

    – Stephen Kitt
    Jun 23 '17 at 20:31


















1














You can use sudo to edit the file using a simple text editor such as nano or kate



sudo kate /etc/apt/sources.list



or if that doesn't work: sudo nano /etc/apt/sources.list



You should be able to then uncomment what you need and save.

This link will help with default lists: https://wiki.debian.org/SourcesList






share|improve this answer
























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f372736%2fhow-to-edit-sources-list-as-root-under-debian-9%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Since you have sudo working, you should use sudoedit:



    SUDO_EDITOR="gedit -w" sudoedit /etc/apt/sources.list





    share|improve this answer

























    • That only works as 2 separate commands. sudoedit /etc/apt/sources.list almost worked - I tried to save it with ctrl+o (it confusingly only said ^O) but then it asks me for the filename with only strange options instead of an option to replace the original file. How can I replace it? Furthermore I can't open the root console anymore - the screen only flickers black after I enter the password.

      – mYnDstrEAm
      Jun 22 '17 at 15:32











    • Let us continue this discussion in chat.

      – Arrow
      Jun 23 '17 at 4:50











    • Seriously, it’s a single command. If you want to make it two, first you need to export SUDO_EDITOR="gedit -w", then sudoedit /etc/apt/sources.list.

      – Stephen Kitt
      Jun 23 '17 at 20:31















    1














    Since you have sudo working, you should use sudoedit:



    SUDO_EDITOR="gedit -w" sudoedit /etc/apt/sources.list





    share|improve this answer

























    • That only works as 2 separate commands. sudoedit /etc/apt/sources.list almost worked - I tried to save it with ctrl+o (it confusingly only said ^O) but then it asks me for the filename with only strange options instead of an option to replace the original file. How can I replace it? Furthermore I can't open the root console anymore - the screen only flickers black after I enter the password.

      – mYnDstrEAm
      Jun 22 '17 at 15:32











    • Let us continue this discussion in chat.

      – Arrow
      Jun 23 '17 at 4:50











    • Seriously, it’s a single command. If you want to make it two, first you need to export SUDO_EDITOR="gedit -w", then sudoedit /etc/apt/sources.list.

      – Stephen Kitt
      Jun 23 '17 at 20:31













    1












    1








    1







    Since you have sudo working, you should use sudoedit:



    SUDO_EDITOR="gedit -w" sudoedit /etc/apt/sources.list





    share|improve this answer















    Since you have sudo working, you should use sudoedit:



    SUDO_EDITOR="gedit -w" sudoedit /etc/apt/sources.list






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 23 '17 at 20:29

























    answered Jun 22 '17 at 15:22









    Stephen KittStephen Kitt

    176k24401479




    176k24401479












    • That only works as 2 separate commands. sudoedit /etc/apt/sources.list almost worked - I tried to save it with ctrl+o (it confusingly only said ^O) but then it asks me for the filename with only strange options instead of an option to replace the original file. How can I replace it? Furthermore I can't open the root console anymore - the screen only flickers black after I enter the password.

      – mYnDstrEAm
      Jun 22 '17 at 15:32











    • Let us continue this discussion in chat.

      – Arrow
      Jun 23 '17 at 4:50











    • Seriously, it’s a single command. If you want to make it two, first you need to export SUDO_EDITOR="gedit -w", then sudoedit /etc/apt/sources.list.

      – Stephen Kitt
      Jun 23 '17 at 20:31

















    • That only works as 2 separate commands. sudoedit /etc/apt/sources.list almost worked - I tried to save it with ctrl+o (it confusingly only said ^O) but then it asks me for the filename with only strange options instead of an option to replace the original file. How can I replace it? Furthermore I can't open the root console anymore - the screen only flickers black after I enter the password.

      – mYnDstrEAm
      Jun 22 '17 at 15:32











    • Let us continue this discussion in chat.

      – Arrow
      Jun 23 '17 at 4:50











    • Seriously, it’s a single command. If you want to make it two, first you need to export SUDO_EDITOR="gedit -w", then sudoedit /etc/apt/sources.list.

      – Stephen Kitt
      Jun 23 '17 at 20:31
















    That only works as 2 separate commands. sudoedit /etc/apt/sources.list almost worked - I tried to save it with ctrl+o (it confusingly only said ^O) but then it asks me for the filename with only strange options instead of an option to replace the original file. How can I replace it? Furthermore I can't open the root console anymore - the screen only flickers black after I enter the password.

    – mYnDstrEAm
    Jun 22 '17 at 15:32





    That only works as 2 separate commands. sudoedit /etc/apt/sources.list almost worked - I tried to save it with ctrl+o (it confusingly only said ^O) but then it asks me for the filename with only strange options instead of an option to replace the original file. How can I replace it? Furthermore I can't open the root console anymore - the screen only flickers black after I enter the password.

    – mYnDstrEAm
    Jun 22 '17 at 15:32













    Let us continue this discussion in chat.

    – Arrow
    Jun 23 '17 at 4:50





    Let us continue this discussion in chat.

    – Arrow
    Jun 23 '17 at 4:50













    Seriously, it’s a single command. If you want to make it two, first you need to export SUDO_EDITOR="gedit -w", then sudoedit /etc/apt/sources.list.

    – Stephen Kitt
    Jun 23 '17 at 20:31





    Seriously, it’s a single command. If you want to make it two, first you need to export SUDO_EDITOR="gedit -w", then sudoedit /etc/apt/sources.list.

    – Stephen Kitt
    Jun 23 '17 at 20:31













    1














    You can use sudo to edit the file using a simple text editor such as nano or kate



    sudo kate /etc/apt/sources.list



    or if that doesn't work: sudo nano /etc/apt/sources.list



    You should be able to then uncomment what you need and save.

    This link will help with default lists: https://wiki.debian.org/SourcesList






    share|improve this answer





























      1














      You can use sudo to edit the file using a simple text editor such as nano or kate



      sudo kate /etc/apt/sources.list



      or if that doesn't work: sudo nano /etc/apt/sources.list



      You should be able to then uncomment what you need and save.

      This link will help with default lists: https://wiki.debian.org/SourcesList






      share|improve this answer



























        1












        1








        1







        You can use sudo to edit the file using a simple text editor such as nano or kate



        sudo kate /etc/apt/sources.list



        or if that doesn't work: sudo nano /etc/apt/sources.list



        You should be able to then uncomment what you need and save.

        This link will help with default lists: https://wiki.debian.org/SourcesList






        share|improve this answer















        You can use sudo to edit the file using a simple text editor such as nano or kate



        sudo kate /etc/apt/sources.list



        or if that doesn't work: sudo nano /etc/apt/sources.list



        You should be able to then uncomment what you need and save.

        This link will help with default lists: https://wiki.debian.org/SourcesList







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 19 at 14:09









        mYnDstrEAm

        79151445




        79151445










        answered Jun 23 '17 at 19:45









        leviataintleviataint

        165




        165



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f372736%2fhow-to-edit-sources-list-as-root-under-debian-9%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay