How to reinstall network manager without internet access?

Solution 1:

sudo dhclient eth0

then you will have internet and you can use...

sudo apt-get install network-manager

Solution 2:

If you've recently upgraded your network manager you can use sudo apt-get install --reinstall network-manager, but this only works if the package is still in your Apt cache (/var/cache/apt/archives/). I'm guessing you haven't so you'll have to do things the long way, but I thought I'd throw that in just in case.

  1. Boot a Ubuntu live CD in "Try without installing". Make sure you are connected to the internet.

  2. In terminal type:

    sudo mount --bind /dev /<chrootlocation>/dev
    sudo mount --bind /proc /<chrootlocation>/proc
    sudo mount --bind /sys /<chrootlocation>/sys
    sudo cp /etc/resolv.conf /<chrootlocation>/etc/resolv.conf
    sudo chroot /<chrootlocation>
    

    You will need to replace <chrootlocation> with the appropriate location of your Ubuntu install, typically the label of the partition it's installed on. The partition must also be mounted so that you can access it.

  3. Edit your /etc/resolve.conf and add at least one nameserver:

    nameserver 8.8.8.8 # Google Public DNS
    
  4. In terminal type:

    sudo apt-get update
    sudo apt-get install network-manager
    

    If you don't you'll likely get an unable to connect error.

  5. In terminal type exit. This exits you from the chroot environment.

  6. In terminal type sudo reboot to reboot your computer.

Solution 3:

This answer assumes that you had internet access before losing network-manager or any other packages.

Live CD/DVD/USB

Create a bootable Ubuntu CD/DVD or USB stick, boot from it and select "Try Ubuntu without installing". Once you get to the Ubuntu desktop, open a terminal.

Root Partition

You need to find out your root partition on your Ubuntu installation. On a standard Ubuntu installation, the root partition is "/dev/sda1", but it may be different for you. To figure out what's the root partition, run the following command:

sudo fdisk -l

This will display a list of hard disks and partitions from which you'll have to figure out which one is the root partition. Below in step 3, ROOT-PARTITION is the root partition you just found, for example /dev/sda2 in my case.

Chroot Into Your Root Partition

To make sure a certain partition is the root partition, you can mount it. So let's mount the root partition along with the /sys, /proc, /run and /dev partitions and enter chroot:

sudo mount ROOT-PARTITION /mnt
for i in /sys /proc /run /dev /dev/pts; do sudo mount --bind "$i" "/mnt$i"; done
sudo cp /etc/resolv.conf /mnt/etc/
sudo chroot /mnt

If you get an error about resolv.conf being identical when copying it, just ignore it. Copying resolv.conf gets the network working, at least for me (using DHCP).

Update/Install Packages

Now you can update the system - in the same terminal, type:

apt-get update
apt-get upgrade
apt-get install network-manager network-manager-gnome

If you have problems on the last step, make sure your sources are correct in /etc/apt/sources.list - in the same terminal, type:

sudo nano /etc/apt/sources.list

Since you've chrooted into your Ubuntu installation, the changes you make affect it and not the Live CD, as long as all changes are made in the same terminal session.

Reboot when finished and remove the Live CD. If this answer fixes your problem, please mark it correct. Thanks!