97

I just installed PHP on Ubuntu Natty from source.

I'm trying to use PECL to install additional modules like APC and Memcache. I'm using something like this:

pecl install apc

However, I get prompts asking me to confirm things.

How can I use the pecl command to just accept the defaults? I saw something like this on a message board: printf "yes\n" | pecl install pecl_http. However, in the case of APC this would answer yes for things where the default is no (I think).

2
  • 1
    @Gordon: I tried that but there doesn't seem to be a handle for what I need.
    – ObiHill
    Nov 15, 2011 at 19:37
  • 1
    For the case where the default values are acceptable, in non interactive mode, PECL prompt is not required. For example, if you add to a Dockefile RUN pecl install apc, at build time, you'll get the default values automatically selected.
    – Dereckson
    Apr 21, 2015 at 22:08

4 Answers 4

97

The following code seems to work ok:

printf "\n" | pecl install apc

You can also replace apc with any other PECL package.

Cheers.

3
  • 9
    I'm also seeing success with yes | pecl install memcache -- although I suppose your solution works better for packages where the default is something other than "yes" Oct 9, 2013 at 16:41
  • 1
    Thanks dude, this even worked with CircleCI Aug 13, 2014 at 15:46
  • Worked for me since I'm installing the extension in a docker container! Thanks! Jan 1 at 15:03
94

The "yes" command can do more than just type "yes"; it can type anything you want, over and over. Including an empty line, which is a good way to accept defaults.

I just needed this myself, so here is what worked well for me:

yes '' | pecl install -f apc
4
  • Thanks for the input, Tom. Was your code meant to be "yes\n" | pecl install -f apc?!
    – ObiHill
    Feb 12, 2014 at 7:39
  • 4
    @ObinwanneHill: Tom was referring to the yes command. The benefit of this over printf is that it generates output repeatedly, which makes it more portable should the pecl installer prompt for additional questions than your scripted printf expected.
    – jmikola
    Apr 9, 2014 at 6:53
  • @jmikola Oh I see, was not familiar with that command. Thanks
    – ObiHill
    Apr 9, 2014 at 7:03
  • 1
    The problem comes when you want a NO instead of a YES in any of the options
    – ln -s
    Nov 9, 2022 at 19:56
16

If you don't want give the same answer for every single prompt ("yes", "no", or ""), you can use --configureoptions to set specific values for each option (see the PECL manual).

You'll want to find your package's package.xml file to see what options are configurable. As an example, for the memcached package, you'd go here:

https://github.com/php-memcached-dev/php-memcached/blob/master/package.xml

Search for the <configureoption> tags, which in this case are:

<configureoption name="with-libmemcached-dir"     prompt="libmemcached directory"     default="no"/>
<configureoption name="with-zlib-dir"             prompt="zlib directory"             default="no"/>
<configureoption name="with-system-fastlz"        prompt="use system fastlz"          default="no"/>
<configureoption name="enable-memcached-igbinary" prompt="enable igbinary serializer" default="no"/>
<configureoption name="enable-memcached-msgpack"  prompt="enable msgpack serializer"  default="no"/>
<configureoption name="enable-memcached-json"     prompt="enable json serializer"     default="no"/>
<configureoption name="enable-memcached-protocol" prompt="enable server protocol"     default="no"/>
<configureoption name="enable-memcached-sasl"     prompt="enable sasl"                default="yes"/>
<configureoption name="enable-memcached-session"  prompt="enable sessions"            default="yes"/>

You can then pass these options along to the install command like so:

pecl install --configureoptions 'with-libmemcached-dir="no" with-zlib-dir="no" with-system-fastlz="no" enable-memcached-igbinary="yes" enable-memcached-msgpack="no" enable-memcached-json="no" enable-memcached-protocol="no" enable-memcached-sasl="yes" enable-memcached-session="yes"' memcached
9

Obinwanne's Hill answer nailed it for me, so I'm not providing anything new here, but the following seems like the absolute shortest also without any fancy tools.

echo '' | pecl install apc
2
  • 6
    A shorter alternative to achieve the same result is: pecl install apc <<<''
    – Guss
    May 16, 2017 at 7:57
  • You can go even shorter echo | pecl install apc, without the ''. Cheers!!
    – John Siu
    Feb 1, 2022 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.