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

前端 未结 8 1256
一整个雨季
一整个雨季 2020-12-31 07:59

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

相关标签:
8条回答
  • 2020-12-31 08:13

    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.

    0 讨论(0)
  • 2020-12-31 08:19

    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.

    0 讨论(0)
  • 2020-12-31 08:20

    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 
    
    0 讨论(0)
  • 2020-12-31 08:21

    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

    0 讨论(0)
  • 2020-12-31 08:31

    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.

    0 讨论(0)
  • 2020-12-31 08:33

    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.

    0 讨论(0)
提交回复
热议问题