Sometimes, we want to run Ubuntu in live mode and test a few programs or commands that need to be installed first. Ubuntu supports installing packages in a live session in the same way as in a fully installed setup.
However, when trying to install package in a live session, often times the following error
E: Unable to locate package xyz
The above error message shows up because by default, a lot of the repositories are disabled in a live session. In order to install packages we need to first enable repositories.
To enable main repository:
sudo add-apt-repository main
To enable universe repository:
sudo add-apt-repository universe
To enable multiverse repository:
sudo add-apt-repository multiverse
To enable restricted repository:
sudo add-apt-repository restricted
Now you can install whatever package you want, provided that its available in one of the repositories:
sudo apt-get install package
Live session vs Persistence
The packages would not be installed on the live media itself and would not persist when you boot the same live usb next time. The packages are only installed during the particular session and everything is gone once you shutdown.
If you want the package to be installed on the live usb and stay persistent, then you need to create "ubuntu usb drive with persistence" which uses a storage file to write all changes made during the live session and keep them persistent during next boot.