<?xml version='1.0' encoding="UTF-8"?>
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
<guide link="/proj/en/portage/doc/manually-fixing-portage.xml">
<title>Manually fixing broken portage installations</title>
<author>
  <mail link="genone@gentoo.org">Marius Mauch</mail>
</author>

<abstract>
This document attempts to help people to manually fix a broken sys-apps/portage 
installation.
</abstract>

<license/>

<version>0.1</version>
<date>19 Feb 2006</date>

<chapter>
<title>Manually fixing portage</title>

<section>
<title>Purpose</title>
<body>
<p>This section will tell you how to manually update/fix your portage installation
in case you can't run <c>emerge sys-apps/portage</c>. While not hard it is still to be done
with great care, so please follow the listed steps exactly (but apply common sense 
when necessary).</p>
</body>
</section>

<section>
<title>Getting a portage tarball</title>
<body>
<p>The first step to do is to get the tarball of a current portage version. In
the following text we will use <e>portage-2.1-r2</e> as an example (as this 
is the current stable version at the time of this writing), please replace that
with a version present in the tree.</p>
<p>Depending on the exact reason portage doesn't work for you anymore it may still
be possible to use it to fetch the tarball for you, so as a first step please
try to run <c>emerge --fetchonly sys-apps/portage</c>, only if that doesn't work
you have to manually fetch the tarball with:</p>
<pre caption="fetching portage tarball with wget">
wget -P /usr/portage/distfiles http://distfiles.gentoo.org/distfiles/portage-2.1-r2.tar.bz2
</pre>
<p>After that you should have the tarball available as 
<path>/usr/portage/distfiles/portage-2.1-r2.tar.bz2</path>.</p>
</body>
</section>

<section>
<title>Replacing the installed version</title>
<body>
<p>The next step is to unpack the tarball to a temporary location, using
<path>/root/portage-recover</path> as example the commands to do that are:</p>
<pre caption="unpacking portage tarball">
cd /root
mkdir portage-recover
cd portage-recover
tar xfj /usr/portage/distfiles/portage-2.1-r2.tar.bz2
</pre>
<p>After you have done this it's just a matter of replacing the python and bash 
files of your existing installation with the ones from the tarball (in most cases
anyway). To do so please run:</p>
<pre caption="replacing installed files">
cd /root/portage-recover/portage-2.1-r2
cp -R pym bin /usr/lib/portage/
</pre>
<p>Now you should have a working portage install again. To ensure a consistent 
system state however you should now run <c>emerge sys-apps/portage</c> again
immediately.</p>
<p>If you get a <c>command not found</c> error message when you try to run
<c>emerge</c> you have to recreate the symlink:</p>
<pre caption="recreating the emerge symlink">
ln -s ../lib/portage/bin/emerge /usr/bin/emerge
</pre>
<p>If these steps didn't work for you your problem is likely not a broken portage 
installation but something else beyond the scope of this document. Please recheck
the <uri link="common-problems.xml">list of common problems</uri> and also look
in <uri link="http://bugs.gentoo.org">bugzilla</uri> if the problem is reported 
there.</p>
</body>
</section>

</chapter>

</guide>
