Amazon Linux doesn’t offer the Gimp Tool Kit (GTK+) so if you want to run Firefox on an Amazon Linux system, say for Selenium testing, you are left having to compile the system yourself. Luckily you have found this post. Create the script below, run it as root and it will build all the components needed for GTK+ and its dependencies for Firefox to run just fine on the system.
vi ./gtk-firefox
chmod 755 ./gtk-firefox
sudo ./gtk-firefox
After you have built the packages, add the /usr/local/bin to your path by updating your .bashrc file.
cat << EOF >> ~/.bashrc PATH=/usr/local/bin:\$PATH export PATH EOF
Here is the gtk-firefox file for your pleasure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# GTK+ and Firefox for Amazon Linux | |
# Written by Joseph Lawson 2012-06-03 | |
# http://joekiller.com | |
# https://joekiller.com/2012/06/03/install-firefox-on-amazon-linux-x86_64-compiling-gtk/ | |
# chmod 755 ./gtk-firefox.sh | |
# sudo ./gtk-firefox.sh | |
TARGET=/usr/local | |
function init() | |
{ | |
export installroot=$TARGET/src | |
export workpath=$TARGET | |
yum –assumeyes install make libjpeg-devel libpng-devel \ | |
libtiff-devel gcc libffi-devel gettext-devel libmpc-devel \ | |
libstdc++46-devel xauth gcc-c++ libtool libX11-devel \ | |
libXext-devel libXinerama-devel libXi-devel libxml2-devel \ | |
libXrender-devel libXrandr-devel libXt dbus-glib \ | |
libXdamage libXcomposite | |
mkdir -p $workpath | |
mkdir -p $installroot | |
cd $installroot | |
PKG_CONFIG_PATH="$workpath/lib/pkgconfig" | |
PATH=$workpath/bin:$PATH | |
export PKG_CONFIG_PATH PATH | |
bash -c " | |
cat << EOF > /etc/ld.so.conf.d/firefox.conf | |
$workpath/lib | |
$workpath/firefox | |
EOF | |
ldconfig | |
" | |
} | |
function finish() | |
{ | |
cd $workpath | |
wget -r –no-parent –reject "index.html*" -nH –cut-dirs=7 http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/linux-x86_64/en-US/ | |
tar xvf firefox* | |
cd bin | |
ln -s ../firefox/firefox | |
ldconfig | |
} | |
function install() | |
{ | |
wget $1 | |
FILE=`basename $1` | |
if [ ${FILE: -3} == ".xz" ] | |
then tar xvfJ $FILE | |
else tar xvf $FILE | |
fi | |
SHORT=${FILE:0:4}* | |
cd $SHORT | |
./configure –prefix=$workpath | |
make | |
make install | |
ldconfig | |
cd .. | |
} | |
init | |
install ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.xz | |
install http://download.savannah.gnu.org/releases/freetype/freetype-2.4.9.tar.gz | |
install http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.9.0.tar.gz | |
install http://ftp.gnome.org/pub/gnome/sources/glib/2.32/glib-2.32.3.tar.xz | |
install http://cairographics.org/releases/pixman-0.26.0.tar.gz | |
install http://cairographics.org/releases/cairo-1.12.2.tar.xz | |
install http://ftp.gnome.org/pub/gnome/sources/pango/1.30/pango-1.30.0.tar.xz | |
install http://ftp.gnome.org/pub/gnome/sources/atk/2.4/atk-2.4.0.tar.xz | |
install http://ftp.gnome.org/pub/GNOME/sources/gdk-pixbuf/2.26/gdk-pixbuf-2.26.1.tar.xz | |
install http://ftp.gnome.org/pub/gnome/sources/gtk+/2.24/gtk+-2.24.10.tar.xz | |
finish | |
# adds the /usr/local/bin to your path by updating your .bashrc file. | |
cat << EOF >> ~/.bashrc | |
PATH=/usr/local/bin:\$PATH | |
export PATH | |
EOF |
If you are running OSX Mountain Lion or above and cannot get Firefox to run via the SSH -X command, make sure you have XQuartz installed as Apple removed X11 by default.
Edited to make Firefox latest release more reliable. Updated with Gist.
Edit 11/21/2012: Added dbus-glib dependency to gist. Added notes about running on OSX
For the firefox tarbal, i think it’s better to use this URL: http://download.mozilla.org/?product=firefox-13.0.1&os=linux&lang=en-US
Current one yields 404
Ah, I guess I need to retract that comment. It probably a 32bit link. You just need to update the link to http://releases.mozilla.org/pub/mozilla.org/firefox/releases/13.0.1/linux-x86_64/en-US/firefox-13.0.1.tar.bz2
Thanks
Thanks for the comment. I wanted to include the download.mozilla.org link but as you found it isn’t very reliable. Further, for me at least, it always downloaded a Windows client even though I specified Linux. I changed the wget command to be a little more reliable and current. It now points to the latest and recursively gets anything in there ignoring indexes and parent links.
Note that on the wget command the trailing slash is important otherwise you start getting stuff in the parent directory and end up with whatever language is last that it downloads.
BTW, what missing on my machine was libstdc++, and libXRender. Installable via yum. Maybe other reader may face the same issue.
I’ll double check these dependencies. Thanks!
Why not simply do “yum install firefox” instead?
Because as the first sentence in the article states, “Amazon Linux doesn’t offer the Gimp Tool Kit (GTK+) so if you want to run Firefox on an Amazon Linux system, say for Selenium testing, you are left having to compile the system yourself.”
Have you tried yum install firefox on Amazon linux? It doesn’t work.
Hey @joekiller, your solution is the only one which worked for me, thanks a lot for the contribution.
I created a gist to keep it updated! 😉
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gtk-firefox.sh
hosted with ❤ by GitHub
Thanks Pablo. I had the same idea but never posted it. I got lost while considering how to implement a version that would at at least pull the “LATEST” links from the gnome.org sources. Another idea was to just make a continuous build of the packages for everyone so no more compilation. I’ll use your gist but here was mine: https://gist.github.com/3991486
Can you tell me after this set up, where is the .mozilla folder located? I want to use the default file… thanks for your effort to write this up!
Bin,
By default the .mozilla folder should end up in the user’s home directory that is running firefox. Try looking at your home directory with the command “ls -alt ~”.
You can also specify a profile location by running “firefox -profile ” where profile path is a directory that you want the profile to be stored in such as ~/mozilla-profile.
Finally you can also run the profile manager with “firefox -p”. If that doesn’t work or it crashes, try “firefox -p -safe-mode”.
Hi joekiller,
Thank you for your post. I have followed step to install firefox on AWS EC2 Linux AMI. The installation is success. But, I get this error when I want to run
XPCOMGlueLoad error for file /usr/local/firefox/libxpcom.so:
libdbus-glib-1.so.2: cannot open shared object file: No such file or directory
Couldn’t load XPCOM.
What should I do?
Thank you
Normally that dependency is taken care of by dbus-glib. Can you confirm it is installed? Try an “apt-get install dbus-glib” to fix the issue.
Hi joe,
Thanks for reply. You are correct. I need to install dbus-glib. But, after that it shows another “lib” error. I tried to install pango-devel to solve libpangoft. It shows libgtk error then. Anyway, I use Amazon Linux AMI which means I use Redhat 4.4.
First of all, make sure you are on a 64-bit machine. These instructions are for 64-bit only. That aside if you are 64-bit, try rerunning the script and looking for compilation errors.
Do you install the firefox on non-gui machine? Sorry, I haven’t told you that I need to install firefox on non-gui machine in purpose to run selenium headless
Thank you so much 😀
Got linux firefox window to show up on Mountain Lion (XQuartz) Display. Everything looks great, but it does not take mouse or key board inputs, any ideas what are missing? Thanks.
I think this has to do with SSH meta key mappings. Check out this article here: http://stackoverflow.com/questions/12190349/alt-key-not-working-in-emacs-sshing-x11
Joe, you rock. For real.
I was trying to set a Selenium headless server for 4 days, almost giving up. Thx, dude. I owe you a beer.
Hi Joe, thanks for the tutorial. I’ve follow your instruction and after I typed “firefox” in the terminal and got this message below:
====================================================================
(firefox:19443): Gtk-WARNING **: Locale not supported by C library.
Using the fallback ‘C’ locale.
Error: cannot open display: localhost:10.0
====================================================================
I’m new to linux, please help me.
I think you are seeing two errors here. The first warning is just a warning so you can ignore it.
The second indicates that you are doing X forwarding properly. Do a search for xforwarding on your OS.
@joe – thanks for posting this. saved me hours.
Joe,
Very weird question. How long the script would take to execute and finish with average speed internet connection?. I am executed the script some 5 hours back but still it is running. Is something going wrong?
I’m not sure why the internet connection would matter if you are running this on Amazon Linux. If you are running a local OS installing firefox via the package manager might be the easiest.
This script is great, the best solution on the whole world-wide web for sure. I have used it 4 times so far.
1 little correction I had to make:
-tar xvf firefox*
+tar xvf firefox*tar*
because there is also a firefox-22.0.json file in the download
Thanks for making my life easier – Maia
Joe,
Many thanks for your tips. Unfortunately I’m on 32-bit. Could you shed some light on this very briefly?
I’ve never run this in a 32-bit environment but the link to firefox is a 64bit release, so try linking to the 32-bit firefox
Joe, my question is if we are running selenium headless using x server display, would we still need this?
if you want to drive firefox I think you do need it. If you don’t please let me know!
Using the latest version of the Amazon Linux AMI (2013.09) I was getting this error after running this script:
XPCOMGlueLoad error for file /usr/local/firefox/libxul.so:
libasound.so.2: cannot open shared object file: No such file or directory
Couldn’t load XPCOM.
Running “yum install alsa-lib-devel -y” fixed it
It looks like Firefox is changing to host on a CDN. The finish() part will give a 404 and fail (even though this was the more reliable and current way to download). Unfortunately, this is no longer true “It now points to the latest and recursively gets anything in there ignoring indexes and parent links.”
I tried to find the exact equivalent on the CDN. However, “latest” is a directory that still includes the version “firefox-26.0.tar.bz2.” So, the version is still necessary.
Still, replacing line 42 with the following will put things back on track (at least for version 26.0):
wget -r –no-parent –reject “index.html*” -nH –cut-dirs=7 http://download-installer.cdn.mozilla.net/pub/firefox/releases/26.0/linux-x86_64/en-US/firefox-26.0.tar.bz2
I will see if I can make a pull request against the gist.
Thank you! Check other forks of the script as well. Some people have improved it in a number of ways. I’ll update the script with everyone’s improvements sometime in the future… I hope 🙂
Still compiling on a micro instance from AWS after 1 hour?!
If it does work I’ll have to save it as an image…
Excellent script Joe. It saves me from digging into the dependency loop!
HI The build has been going on forever. How long does it take
It could take up to a few hours if you have limited CPU.
Excellent work, sir! A year old solution that still works!
This method worked perfectly up until today, thank you very much for it! Now for some reason I’m getting following error: “Xvfb: symbol lookup error: Xvfb: undefined symbol: pixman_glyph_cache_create” no matter what I do. Just recreated instance from scratch following these instructions (had to change URL for Firefox) and still getting this error. Any advice?
I’m not sure but I did just update the script for some missing dependencies (AWS is always making their distro lighter) and was able to get everything going using amzn-ami-hvm-2014.09.1.x86_64-ebs (ami-b66ed3de)
Hello Joe, thank you very much for the reply! I just did everything from scratch again (I was on a different zone, so I switched to East to get exactly ami-b66ed3de), and get the same error. Here are the commands I input:
wget https://gist.githubusercontent.com/joekiller/4144838/raw/ab80fee4f9b40c71090b72f2f8539934b24b0722/gtk-firefox.sh
chmod 777 gtk-firefox.sh
sudo sh gtk-firefox.sh
sudo yum install Xvfb
export DISPLAY=:1
Xvfb :1 -screen 0 1280x768x24 &
firefox
And the result is:
Xlib: extension “RANDR” missing on display “:1”.
Xvfb: symbol lookup error: Xvfb: undefined symbol: pixman_glyph_cache_create
firefox: Fatal IO error 11 (Resource temporarily unavailable) on X server :1.
[1]+ Exit 127 Xvfb :1 -screen 0 1280x768x24
I am stuck.
For those still experiencing this problem: http://superuser.com/questions/870702/aws-ec2-linux-headless-firefox-issue-xvfb-undefined-symbol-pixman-glyph-cache/876285#876285
Delete /usr/local/lib/libpixman-1.so.0
Solved it for me.
The Screen stucks after many initialization lines.
Here is the log
Initializing built-in extension Generic Event Extension
Initializing built-in extension SHAPE
Initializing built-in extension MIT-SHM
Initializing built-in extension XInputExtension
Initializing built-in extension XTEST
Initializing built-in extension BIG-REQUESTS
Initializing built-in extension SYNC
Initializing built-in extension XKEYBOARD
Initializing built-in extension XC-MISC
Initializing built-in extension SECURITY
Initializing built-in extension XINERAMA
Initializing built-in extension XFIXES
Initializing built-in extension RENDER
Initializing built-in extension RANDR
Initializing built-in extension COMPOSITE
Initializing built-in extension DAMAGE
Initializing built-in extension MIT-SCREEN-SAVER
Initializing built-in extension DOUBLE-BUFFER
Initializing built-in extension RECORD
Initializing built-in extension DPMS
Initializing built-in extension Present
Initializing built-in extension X-Resource
Initializing built-in extension XVideo
Initializing built-in extension XVideo-MotionCompensation
Initializing built-in extension SELinux
Initializing built-in extension GLX
Xlib: extension “RANDR” missing on display “:1”.
Please help me
I got this too looks fine to me. How come this is from 2012, what are people doing now?
Hi,
Thanks for GTK 2 as we used your gtk to install firefox 45 but our seleinum driver 2.52.0 is not comatabile with firefox 45 we need to install firefox 47 but as this require GTK 3+ library.
We are using LInux AMI and cant move to ubuntu due to organisation standards only option left is compile GTK 3 our self at below link
http://www.linuxfromscratch.org/blfs/view/svn/x/gtk3.html
https://developer.gnome.org/gtk3/stable/gtk-building.html
But we are not able to do that due to some expertise lack in linux
So can you suggest any script for that that install and compile GTK3 in Amazone AMI to run the firefox 47 version.
Please respond its urgent
Have you solved that issue?
Not yet
HI Joe,
Thanks a lot for this script. I have run the script in EC2 and it ran for some time but exited with below error—2018-05-15 11:34:22– http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/linux-x86_64/en-US/
Resolving download.cdn.mozilla.net (download.cdn.mozilla.net)… 23.48.157.193, 2600:1409:a:595::201c, 2600:1409:a:586::201c
Connecting to download.cdn.mozilla.net (download.cdn.mozilla.net)|23.48.157.193|:80… connected.
HTTP request sent, awaiting response… 302 Moved Temporarily
Location: http://download-origin.cdn.mozilla.net/pub/firefox/releases/latest/linux-x86_64/en-US/ [following]
–2018-05-15 11:34:23– http://download-origin.cdn.mozilla.net/pub/firefox/releases/latest/linux-x86_64/en-US/
Resolving download-origin.cdn.mozilla.net (download-origin.cdn.mozilla.net)… 13.32.252.94, 2600:9000:20d3:3200:e:8dab:f807:c041, 2600:9000:20d3:5800:e:8dab:f807:c041, …
Connecting to download-origin.cdn.mozilla.net (download-origin.cdn.mozilla.net)|13.32.252.94|:80… connected.
HTTP request sent, awaiting response… 404 Not Found
2018-05-15 11:34:23 ERROR 404: Not Found.
tar: firefox*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
Any help is appreiciated
The problem is the origin from where your trying to download firefox : https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US , this is the correct one in todays days, unfortunally i doesn’t work for me the installation, any one in 2019 have install firefox in amazon linux?