# How to upgrade libpcre for CentOS 7

Categories: Software Use Uncategorized

Ok, this is the problem:

if we need higher version of library in CentOS, how should we get it if it’s not in any repository?

So, after a long time study, I found the only way is to compile it by myself. Actually, it’s not a big problem. But the thing is libpcre is a widely used package in CentOS. By running yum remove libpcre, you will realize that. So we couldn’t use yum to help us do that. What can we do?

*   Step 0: BACKUP ALL YOU LIBPCRE LIBRARIES INSTALLED. This is an very important step but I found most tutorial online didn’t mention that, which will results a disaster if you don’t do that. The way I do it is very simple.

1.  Run rpm -ql pcre which will give you the location of the libraries

2.  Copy these files to a location, like what I did cp /usr/lib64/libpcre.so.1 /root/ actually this is the only lib needed

*   Step 1: remove installed libpcre

1.  Run rpm -qa | grep -i pcr and get the packages installed related to pcre

2.  Run rpm -e --nodeps "XXX " to remove installed pcre, replace XXX by the name of pcre library, for my case, I have pcre-8.32-15.el7_2.1.x86_64

*   Step 2: Ok, you will find you couldn’t use any command now! It’s time to create a symbolic link for the previous lib we backed up. Just run ln -sf /root/libpcre.so.1 /usr/lib64/libpcre.so.1. Note that, you should replace the first argument by the location of the file you backed up and the second by the location where it should be at.

2.  Configure it.

./configure    --libdir=/usr/lib64      &<br /> --docdir=/usr/share/doc/pcre-8.39    &<br /> --enable-unicode-properties          &<br /> --enable-pcre16                      &<br /> --enable-pcre32                      &<br /> --enable-pcregrep-libz               &<br /> --enable-pcregrep-libbz2             &<br /> --enable-pcretest-libreadline        &<br /> --disable-static                     &<br /> --enable-utf8                        &<br /> --enable-unicode-properties

One thing you should keep in mind is that the libdir should be the location where you want the library to be installed. Usually, it should be the same as the directory where the previous library is in. For my CentOS7, the location is /usr/lib64. I guess for 32bit system it might be /usr/lib?

1. Time to make! Just type make first. Once it’s made, type make install to install that.

2. Check if you have a bunch of libpcre* in /usr/lib64, and use readlink /usr/lib64/libpcre.so.1 to double check if it’s correctlly linked to the new compiled file, and ldd /usr/bin/grep to check if the library works correctly

• Step 5: If everthing goes well now, you are DONE!

There isn’t step 4 because I hate number four.