How do I pause/resume download and install from terminal?

76,516

Ctrl+c cancels it but next time start from where you left Ctrl+z stops process but then you can't do another process as it remains locked to the first process

Using one of the above methods is generally better than just closing the terminal, but if you just close the terminal while it's downloading packages, it should start the download right where it stopped next time you run sudo apt-get upgrade

If you want to restart the download after using Ctrl+z:

  1. Check paused tasks by typing jobs in the terminal
  2. To resume a process, type fg
  3. If you have multiple tasks, then type fg 1, fg 2, etc…

Make sure, however, that you never stop it while it's installing the downloaded packages, since this will result in a lock on apt-get, which will require a computer restart or reconfiguration of apt, and you'll have to start at the beginning of the installation. So make sure to only "pause" (close) the terminal when it's downloading, not installing.

If you would like to start another apt-get process - after pausing the first process, run sudo rm /var/lib/dpkg/lock && sudo rm /var/cache/apt/archives/lock; it won't look like it did anything, but you should be able to start another apt-get process.

To kill a command that you've paused with Ctrl+z, enter kill -9 %x into the terminal, replacing x with the number that the paused process is (see jobs). The process will remain in the list, but it will say "killed" after it instead of "stopped", indicating it is no longer active.


Sources : [ubuntu] How to pause download operation in terminal
Accidently pressed Ctrl-Z in a Linux terminal in Ubuntu Intrepid Ipex. What do I do now? Starting, Stopping and Managing Jobs in the Ubuntu Terminal


Share:
76,516

Related videos on Youtube

VedVals
Author by

VedVals

I am a student of Instrumentation and Control AT VIT, Pune, India. I am a Linux enthusiast with a desire to learn whatever I find interesting. I Love to learn new things anytime. I Also like to try to trash my Ubuntu system in as many ways as possible.

Updated on September 18, 2022

Comments

  • VedVals
    VedVals over 1 year

    I mostly use terminal for installation of programs (as does mostly everybody). However, at times (particularly when I have low battery and no charger wire OR more importantly, when installer file is too big, installation is incomplete and I need to power down my system) I would like to pause the installation (while it is in downloading state) so that I won't loose already downloaded files.

    How do I do this?

    • mikewhatever
      mikewhatever over 11 years
      Wouldn't it be simpler not to start a long installation when the battery is low? I thought "everybody" new about that.
    • VedVals
      VedVals over 11 years
      I start installation with considerable battery (mostly >90%). But I have a slow bandwidth connection and a power saving problem. I get max 25 kB/s on downloads (sometimes 30 kB/s at night). Also focus is on the second condition as that is more frequently occurring.
  • VedVals
    VedVals over 11 years
    Tried the answer. Now how to resume?
  • ananaso
    ananaso over 11 years
    @ved2254 Just use fg, assuming you haven't started any other processes. I added it to the answer for consistency.
  • ananaso
    ananaso over 11 years
    I'm not on my home computer right now, so I'll test this when I get home, but typing fg or fg 1 should "unpause" it.
  • VedVals
    VedVals over 11 years
    It works. On a side note, I had to stop it as it couldn't connect to the servers. Does this tend to happen? Tried to install Ubuntu Ultimate Edition Theme Pack
  • ananaso
    ananaso over 11 years
    It couldn't connect to the download servers for Ubuntu Ultimate Edition Theme Pack upon restarting with fg? Or just it couldn't connect to them in general?
  • VedVals
    VedVals over 11 years
    I tried it on only the theme download so don't know if it is general. I suspect it is U-UE specific.
  • VedVals
    VedVals over 11 years
    Also apt-get gets locked. Is there a way I can unlock it to download and install anything else?
  • ananaso
    ananaso over 11 years
    I added the instructions to the post - sudo rm /var/lib/dpkg/lock && sudo rm /var/cache/apt/archives/lock should unlock it, yet keep the old process so you can recall it later. I think it's just with that package, since I anything else I recall with fg runs like normal, without any server errors. Don't really know what else, sorry. :/ Maybe if you start a new thread someone more knowledgeable could take a look at it.
  • Find Me In The Woods
    Find Me In The Woods almost 9 years
    a little confusing. We want apt-get, not wget
  • yainspan
    yainspan over 7 years
    What are you trying to pulse?