I've been told I need to set the following environment variable in order to work around a glib bug:


But I don't know how to do it, and anywhere I've seen it's use recommended, they just take it for granted you know how to do it (even the gnome documentation: https://developer.gnome.org/glib/stable/glib-running.html).

So I tried setting it as a linux environment variable. I tried setting it in the programming environment I was in (Firefox Add-on SDK), but without success.

It seems to me that I may have to install glib development packages and find some sort of config file. But perhaps someone would help before I go up the wrong path?


You set environment variables in a process and they are inherited by all the child processes. Exactly how you go about that depends on where you want it to be available. You don't have to modify any GLib configuration, though.

To set an environment variable for programs started from your shell (I'll assume Bash here), you can write:

export G_SLICE=always-malloc

All programs you start from this shell session after that will have the variable set.

If you want it to be set for every shell you start afterwards, add that line to ~/.profile as well. In that case it will apply to all future shells you start, but not any that are currently running.

To set it for just a single execution of a program (perhaps to debug its effects), precede the command with the variable assignment:

$ G_SLICE=always-malloc gsomething

Those are all for commands you run from the terminal. .profile will generally work for the GUI as well, but that can be broken by system configuration. They're all per-user configuration as well.

If you want it set for every user all the time, you can (likely) add an assignment to /etc/environment. The format is a little different there: just KEY=VAL on separate lines, with no required quoting and none of anything else.


This is (again, likely — system-dependent) parsed by the pam_env module. There is a per-user ~/.pam_environment file as well, which has the same effect for just the one user, but may or may not be enabled on your distribution. These both require logging out and back in for the change to take effect.

Alternatively, you can add the export statement in ~/.xinitrc (if you use startx) or ~/.xsession (for most login managers). KDE supports a directory ~/.kde/env that can contain as many shell files as you want, which contain export statements as above.

  • Thank you for a brilliant, comprehensive answer, Michael. It does answer my question. But does not, alas, solve my problem. I posted my question here, not my problem. I had already done as you said: export G_SLICE=always-malloc. FYI, This did not appear to solve my problem (bugzilla.mozilla.org/show_bug.cgi?id=1057336) as I had been told it would (bugzilla.mozilla.org/show_bug.cgi?id=833117). That's a different question though. Cheers. – markling Aug 25 '14 at 13:37

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.