How can I modify my cygwin environment to use Strawberry Perl instead of the packaged Perl distribution?
Asked Answered
P

8

13

I currently use Strawberry Perl as my primary Perl distribution. However, I have some applications that make Perl calls through cygwin. These generally fail because they are calling the version of Perl that was packaged with cygwin, and only looking in cygwin's lib folders. How can I modify my cygwin environment to call Strawberry Perl (and use the C:/strawberry/perl/lib dirs) instead?

Phenobarbitone answered 21/1, 2009 at 2:45 Comment(0)
E
22

If you remove Perl from cygwin using the setup program it will use Strawberry Perl by default.

If you are unable to remove Perl from cygwin, you can create a symbolic link to the Perl executable from Strawberry.

From a cygwin shell, use the following set of commands:

$ mv /usr/bin/perl /usr/bin/perl-cygwin
$ ln -s /cygdrive/c/strawberry/perl/bin/perl.exe /usr/bin/perl

This is assuming you used the default Strawberry Perl installer. Update your perl.exe location accordingly if you have it installed somewhere else.

Check to make sure the link is working properly by checking the Perl version:

$ perl -v

It should say This is perl, (version) built for MSWin32-x86-multi-thread (or similar) and not built for cygwin-thread-multi-64int.

Erelong answered 21/1, 2009 at 6:18 Comment(1)
I know this was forever ago, but THANKS SO MUCH. This indirectly helped me solve a problem I'd been trying for two days to figure out. I needed the strawberry perl install to execute from cygwin because I needed the strawberry modules, yet I needed cygwin to correctly interpret the program's linux commands (ex "mv").Isometrics
S
2

Many of these are good solutions, but I rather take an easy one that I don't have to modify more than once.

All you need to do is add/modify a line in your .bashrc file.

# Prepend strawberry perl to cygwin's path
export PATH=/cygdrive/C/Tools/Perl/perl/bin:$PATH

source .bashrc file from your shell, (or start a new shell) and run your program.

source ~/.bashrc
perl script.pl 
Sextant answered 20/3, 2015 at 16:48 Comment(1)
This is best practices wise the right answer ;o) , but it wil take some years for some folks to realize it ... ;o)Hosea
M
1

You can change your PATH to put the Strawberry directories first. Strawberry tries to be nice by putting its directories at the end of the PATH. If you installed from the .zip file, however, it didn't change the PATH at all.

You could move /usr/bin/perl, but that's a bad idea since it breaks when cygwin tries to update what it thinks is its perl. I just had that happen to me this week and used to happen to me on my Mac until I stopped playing with the system setup and installed my own stuff completely separate.

Monochord answered 22/1, 2009 at 23:6 Comment(0)
A
1

One good thing I can add is that if you get the right perl to come first in the path, it should handle site-specific CPAN modules you may have installed with strawberry perl running in a CMD shell.

"which perl" is your friend.

If you had trouble with this, you could set the PERL5LIB environment variable, but it shouldn't be necessary.

I still pass in DOS-style file paths as parameters into the perl script, i.e. "d:\data\myfile.txt", not "/cygdrive/d/data/myfile.txt". So oddly enough, this mix of path notation works:

bash> /cygdrive/d/scripts/myscript.pl d:\data\myfile.txt

Adenectomy answered 22/6, 2009 at 14:34 Comment(0)
A
0

This is probably not a preferred solution, but you should be able to modify the #! line:

#!/cygdrive/c/strawberry/perl/bin/perl5.10.0

I always refer to an explicit location and installation of perl, rather than relying on what is in /usr/bin.

Atabrine answered 5/2, 2009 at 17:37 Comment(0)
W
0

I have two scripts that I use to modify the first line of Perl scripts to whichever Perl is first in my path: rightperl hardcodes to the Perl that is first in my $PATH now, envperl will change the line to #!/usr/bin/env perl so the Perl to use is only picked at the time the script is invoked. Works really well under Cygwin (and from a Unix shell in general).

Whet answered 1/4, 2009 at 15:50 Comment(0)
M
0

If you don't want to mess around with any paths or do anything permanent there is an easy TEMPORARY hack. Type "where perl" at Cygwin sh prompt. It will list all the Perl.exe it sees in PATH in their order of execution. Change the names of the ones you don't want to be seen that get listed before the perl you want to use. But DO remember to change them back when you are done or you might have a few problems down the road.

Marjoriemarjory answered 29/4, 2012 at 15:58 Comment(0)
N
-2

I don't have my cygwin machine nearby so I can't test this, but perhaps you can front-end the perl command with a script: go to /bin under cygwin and move the perl.exe there to something else like perl-org.exe, then set up a shell script that execs your other perl with the same arguments.

Nicolina answered 21/1, 2009 at 5:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.