Export packages and import them again

is there a way to export specific packages that are installed in my system and then import them again in a fresh install?
i dont just want to export the packages list which can be done with:
pacman -Qqe > pkglist.txt
and to install the list:
pacman -S --needed - < pkglist.txt
but i need to export the installable packages so as to install it directly without re-downloading it.

but why? Sounds to be a promising way to a broken system…

Hi @ardv,

You could copy the whole cache dircetory, or files from it to back up and then restore it/them. By default in /var/cache/pacman/pkg/.

1 Like

Ideally and even normally you’ll have all the packages still in the cache:
/var/cache/pacman/pkg

Copy them to the same location in the other system and when you use

pacman -S --needed - < pkglist.txt

the packages from the cache will be used - no need to download again

I’m not sure whether --needed is a good idea, though.

you should run:
pacman -Syu first

everything that is already present will not be downloaded again

I do a similar thing all the time with my VM’s - I have a partition, shared among all of them, where the contents of
/var/cache/pacman/pkg
resides
so that each package is only downloaded once and then can be used by all the VM’s

2 Likes

where the contents of /var/cache/pacman/pkg resides

is there a way to change the default pacman cache directory?

Not that I know of - but that doesn’t mean it’s not possible.

But why would you want to do that?

The end result is always the same, no matter where you put it.

Edit /etc/pacman.conf and change the line:

#CacheDir    = /var/cache/pacman/pkg/

Remember to remove the # (comment denominator) in front of it.

2 Likes

i think if i could change it to my /home partition it will be well, so as i can format the system partition without loosing the packages

thank you

as @Mirdarthos said - but the home partition might not be the best place (permissions …)

for temporary storage … to preserve it - why not

and:
just changing the location will not move what is already there - you will have to do that

1 Like

The easy method is to copy the content of /var/cache/pkg/ to USB device.

Another option is a portable mirror

Techinically you would do something like

  • create a list of repo packages installed
  • ensure all packages is present
    sudo pacman -Sw - < pkglist.txt
    
  • prepare some adequate storage
  • copy the packages to the storage
  • on the new system - feed the package list to pacman
    sudo pacman -Syu --cachedir <your-storage> - < pkglist.txt
    
1 Like

when i perform this command:

sudo pacman -Syu --cachedir <your-storage> - < pkglist.txt

the pacman will install the packages from the directory and does not check the online databse? what if the package in the directory is older than the one in the database and i need to install the one in the folder not the new one? or if i go offline and want to install the package?

what if i prefer to just install what is present in that folder and not download new packages -either because i’m offline or the packages are big in size and i dont want to update them to get minor updates-?

everything needed will be there

if not:
partial update would likely be the result
very bad idea™
it will more likely than not break your system if you don’t make a full update due to packages not in cache and your unwillingness to download what is needed

If your new machine or the fresh install runs the same desktop as before,
everything needed will be there - if the last update was not too long ago.

Just move/copy the contents of /var/cache/pacman/pkg/ to somewhere,
install fresh,
copy the saved files back to that directory - done.

You appear to be making it harder than it needs to be.

2 Likes

I’ll just note that this approach, well it is probably the only approach,but still, would require the databases to be the same as well, presuming your current database isn’t the updated one.

To make sure, copy the database files along with the packages. They are located in /var/lib/pacman/sync.

Trust me when I say no to the databases required to be the same.

I don’t even touch them - each system has got it’s own.

This is, as I said, what I use to share the packages in the cache among five different Manjaro virtual machines - each one has got its own set of modifications
but the majority of the packages is the same, since they are all on stable branch

I even share the same cache with an Arch (EOS) installation.
… what is in the package cache doesn’t need to be downloaded again and will be used when available.

Works perfectly fine.

I update Gnome - and then Plasma - some plasma packages need to be fetched, but what is common in the base system is already there.
Same for Xfce etc - saves a lot of redundant downloading and also disk space and time as well.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.