# How to Install Glibc With Only 1 Locale

## Vlad

Howto Install Glibc With Only 1 Locale

Preface

This is to best done during system installation, not after a system has already been built.  I haven't tried doing it on a system that's already up, so take care if you want to try it.  This is designed to shave time off of the bootstrap process by removing the numerous locales which are installed by default (and the vast majority of us will never use).  Also take care to research which locale you're in; I do not at this time know the commands involved to install different locales (other than US English).

1. Just before bootstrapping, determine which version of glibc is going to be installed:

```
# emerge --pretend glibc

These are the packages that I would merge, in order.

Calculating dependencies ...done!

[ebuild  N   ] sys-libs/glibc-2.2.5-r2 to /
```

Take note of the version you are installing; you must edit the correct ebuild script in order to make the changes successfully.  In this example, the version is 2.2.5-r2.

2.  Edit the ebuild script: 

```
# nano -w /usr/portage/sys-libs/glibc/glibc-version.ebuild
```

3.  Search (Control+w) for "localedata".  Add a "#" in the front of the line to comment it out.

This is what the line looks like in 2.2.5-r2:

```
 make PARALLELMFLAGS="${MAKEOPTS}" install_root=${D} localedata/install-locales -C buildhere || die 
```

4.  Below the line you just commented out, add the following:

```
localedef --prefix=${D} -i en_US -f ISO-8859-1 en_US
```

Change the locale as needed; this example shows US English.

5.  Save the build script (Control+O) and exit (Control+X).  Change any compiler flags in /etc/make.conf (if you so wish) and make sure you are in /usr/portage to run the bootstrap.

6.  Begin the bootstrap by issuing the command: 

```
# scripts/bootstrap.sh
```

 This command will NOT work if you are not in the /usr/portage directory!

*Note: If you are on a dialup or slower connection, you can download the files you need to bootstrap by using the following command:

```
# emerge -f glibc binutils gcc zlib
```

(I believe that's all of them; if it's not, will someone let me know please? :))

This will download glibc, binutils, gcc, and zlib, as well as all dependencies.  Doing this will prevent your connection from accidently disconnecting after being idle between wgets, and help minimalize the chance that someone will goof up your internet connection.  This works great if you bootstrap before bedtime; just do make the changes in your ebuild scripts, make sure you're in /usr/portage, and issue the command: 

```
# emerge -f glibc binutils gcc zlib && scripts/bootstrap.sh
```

 Don't worry; if your downloads fail; your bootstrap will NOT be done.[/b]

----------

## Kream

Thanks for the great tip !!!    :Very Happy: 

----------

## toliman

if you would also like to strip locales you have previously installed, there is a masked program called localepurge in the portage tree, janneand added this small python app in a thread about removing locale files to save space

from https://forums.gentoo.org/viewtopic.php?t=24687

```

#!/usr/bin/env python 

# file: clean_locale 

# Script to remove unwanted translations. 

import os, commands 

# Add directories to save here: 

exclude = ['locale.alias', 'C', 'POSIX', 'US_ASCII'] 

path = "/usr/share/locale" 

dirs = os.listdir(path) 

for dir in dirs: 

   if dir not in exclude: 

      print "Removing %s/%s..." % (path, dir) 

      (err, output) = commands.getstatusoutput('rm -rf %s/%s' % (path, dir)) 

      if err: 

         print "Could not remove %s/%s: %s" % (path, dir, output)

```

----------

## diper

I tried the trick shown below in a running installation (not one before the bootstrap stage) and found localedef would not generate the directories under /usr/lib/locale like en_US fr_FR , etc. It only generates the file locale-archive, with the requested locales inside. my questions are:

Is this new?

Is this fine?

Is this a problem? is so, any clue on how to solve it?

are those directories under /usr/lib/locale needed or all the info is kept in the locale-archive file?

Regards.

Diper

 *Vlad wrote:*   

> Howto Install Glibc With Only 1 Locale
> 
> Preface
> 
> This is to best done during system installation, not after a system has already been built.  I haven't tried doing it on a system that's already up, so take care if you want to try it.  This is designed to shave time off of the bootstrap process by removing the numerous locales which are installed by default (and the vast majority of us will never use).  Also take care to research which locale you're in; I do not at this time know the commands involved to install different locales (other than US English).
> ...

 

----------

## bone

I started to do the rebuild of glibc with the localedata stripped down, but decided to try the ebuild localepurge instead. I am sure glad i did as I just noticed the previous post about someone trying it after bootstrap and it not working entirely. See great output from localepurge below.

Total disk space freed by localepurge: 79832K

 :Laughing: 

----------

## johnjohn

Vlad you bastard, you never did give me credit for walking you through this on irc.  I, on the other hand, am happy to give credit to the Linux From Scratch gang from whom I first learned this space-saving procedure.

 *Vlad wrote:*   

> Howto Install Glibc With Only 1 Locale
> 
> *Note: If you are on a dialup or slower connection, you can download the files you need to bootstrap by using the following command:
> 
> ```
> ...

 

These days, of course, bootstrap recognizes the --fetchonly flag, so you can just:

```
# /usr/portage/scripts/bootstrap.sh -f
```

 *Quote:*   

> This works great if you bootstrap before bedtime; just do make the changes in your ebuild scripts, make sure you're in /usr/portage, and issue the command: 
> 
> ```
> # emerge -f glibc binutils gcc zlib && scripts/bootstrap.sh
> ```
> ...

 

Now all you need to do is:

```
# cd /usr/portage

# ./scripts/bootstrap -f && ./scripts/bootstrap.sh
```

And for those of you who like everything downloaded at once:

```
 ./scripts/bootstrap.sh -f && emerge -f system && USE="-gtk -gnome -X" emerge -f vim screen gentoolkit ccache && time ./scripts/bootstrap.sh
```

That ought to keep the "slow connection, fast computer" crowd going for a while.

----------

