Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I work on a Mac, and my default perl version is v5.12.4. For 99% of the time I use a perlbrew install I have, as I for my work need numerous modules I don't want to install on system perl.

Is there a way to automatically switch to that install with bash startup? I tried adding

  perlbrew  switch perl-5.14.2

to .bashrc, but it doesn't seem to work

share|improve this question

migrated from Sep 12 '13 at 22:45

This question came from our site for system and network administrators.

2 Answers 2

A bit late, but for future searchers.

The command is pretty simple in my case I use Linux Centos 6.5 but because it uses perlbrew command I expect the same behavior, if not, just mention.

perlbrew install perl-5.14.2 -n --switch

You have a lot more options to tinker in perlbrew -h have fun!

share|improve this answer
$ perlbrew

    perlbrew command syntax:

        perlbrew <command> [options] [arguments]


        switch         Permanently use the specified perl as default


~$ perlbrew help switch

Usage: perlbrew switch [ <name> ]

Switch to the given version, and makes it the default for this and all
future terminal sessions.

Without a parameter, shows the version of perl currently selected.

You just need to issue your command in a Terminal window:

$ perlbrew switch perl-5.14.2

Then if you do:

$ perlbrew list will see something like:

* perl-5.14.2

The * indicates the default perl.

I'm not sure why your command doesn't work in .bashrc--although the command only needs to be issued once, so putting it .bashrc isn't appropriate anyway. According to this article, Terminal does not execute .bashrc--instead it executes .bash_profile for all shells, so maybe that's why it doesn't work. According to that article, if you want to execute .bashrc, you have to enter some code in .bash_profile to do so.

Another possibility: you spelled your perl's name wrong. To check the spelling, do:

 $ perlbrew list

...then copy and paste the name of the perl that you want to be the default into your switch command.

The way perlbrew works is that it adds the path to a certain perl version onto the front of your PATH environment variable. As you probably know, when you issue a command in a Terminal window, like perl, your OS looks for the command in the directories specified in the PATH environment variable--in the order the directories are specified. As soon as the command is found, your OS stops searching. First match wins!

When the Terminal window closes, perlbrew then removes the path from the front of your PATH environment variable. However, when you use the switch command (v. the use command), perlbrew neglects to remove the path from the front of your PATH environment variable. Therefore, the next time you open a Terminal window and issue the perl command, the command will be found in the first directory specified in your PATH environment variable, which will be the directory for the perl version that you set with the perlbrew switch command.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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