I follow the steps in this post to create a custom repository, but I want to rename it. I can't find any way to do it. Can you please help me?

  • 1
    What do you mean by rename? Repositories don't have names. Do you mean the suite name (e.g bionic/focal)? The component (e.g. main, universe)? The path (e.g. /usr/local/mydebs)? – Stewart Nov 20 '20 at 7:51
  • Let me elaborate on this. I downloaded a package and used the dpkg-scanpackages program, now after changing the sources file I can install the package via apt-get. But the name of this package is beyond my control. I want to name this package say MyRepository, to be able to install it by writing apt-get MyRepository, instead of apt-get AnotherDudesName. – DiplomateProgrammer Nov 20 '20 at 7:58
  • @DiplomateProgrammer What do you mean by repository here? Are you talking about package name? – Amith Nov 20 '20 at 8:15
  • I don't know the terminology. I created a local repository using the dpkg-scanpackages command like in the post I linked. Everything is fine, but there seems to be no way to change the name of the package. – DiplomateProgrammer Nov 20 '20 at 8:21

Sounds like you want to know how to rename a package. There are two ways to do this. In this example, I'm going to change the name of cowsay to mysay

From source

Download the debian (or ubuntu) source package, rename the files as appropriate, replace the old name with the new name in the debian/* directory (that's what the sed lines are doing, then build it with dpkg-buildpackage.

Be a little careful, because some packages may have build rules which depend on the package name and may not be as trivial as cowsay. This is probably the toughest option.

apt source cowsay
mv cowsay-3.03+dfsg2 mysay-3.03+dfsg2
mv cowsay_3.03+dfsg2-8.dsc mysay_3.03+dfsg2-8.dsc
mv cowsay_3.03+dfsg2.orig.tar.gz mysay_3.03+dfsg2.orig.tar.gz
cd mysay-3.03+dfsg2/
sed -i 's/\bcowsay\b/mysay/g' debian/changelog debian/control
sed -i 's./debian/cowsay./debian/mysay.g' debian/rules
dpkg-buildpackage -uc -us

From binary

Get the *.deb you want to manually split the archive up, edit the control file and then put it back togeather.

apt download cowsay
mkdir mysay && cd mysay

# Split everything up
ar -x ../cowsay_3.03+dfsg2-8_all.deb
mkdir control
tar -xf control.tar.xz -C control

# CHange the package name
sed -i 's/cowsay/mysay/' control/control

# Put the control file back togeather
cd control
tar -cf control.tar.xz *
mv control.tar.xz ../
cd ..
rm -r control

# Put the rest back togeather
ar r ../mysay_3.03+dfsg2-8_all.deb debian-binary control.tar.xz data.tar.xz

From binary (method 2)

This one simplifies the re-combining process. This is probably the easiest method.

apt download cowsay
ar x cowsay_3.03+dfsg2-8_all.deb 
mkdir -p mysay/DEBIAN
tar -xf control.tar.xz -C mysay/DEBIAN
tar -xf data.tar.xz -C mysay/
sed -i 's/cowsay/mysay/' mysay/DEBIAN/control
dpkg-deb -b mysay

A few final notes:

  • If you try to install cowsay and mysay on the same machine, one of the packages will fail. That's because they both supply the same files, so it's impossible for your system to know which owns it. A way to make this foolproof is to add a Conflicts: cowsay to the control file of mysay.

  • Renaming packages is a little strange. It is sure to cause the conflicts mentioned above. I not sure I can picture a case where this is necessary.

  • Thanks, I think this addresses my issue. – DiplomateProgrammer Nov 20 '20 at 8:58
  • However, I tried a similar approach with binary before and it didn't work. I changed the control file in the control.tar.xz directory of the archive, changing Package from the original name to my own. But when I call the dpkg-scanpackages command, the control file is once again changed to what it was before and it doesn't work. Update: it seems for some reason there's an archive inside the archive, so that's why it wasn't updated. Probably should work if processed carefully. – DiplomateProgrammer Nov 20 '20 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.