Freebsd11上安裝PERL模組 freebsd11+ perl module

URL Link //n.sfs.tw/13362

2019-06-29 02:21:30 By 張○○

使用PERL時最煩人的就是遇到沒有安裝的模組,例如:

Can't locate DBD/mysql.pm in @INC (you may need to install the DBD::mysql module) (@INC contains: /…) at xxx.pl line xx.

 

在freebsd 11上要安裝pel module,有幾種方式,如cpan, cpanm。

使用pkg安裝

最方便的還是用pkg來裝

列出包含關鍵字的可用模組

例如要列出有關鍵字DBD的模組,使用pkg search DBD

# pkg search DBD
p5-AnyEvent-DBD-Pg-0.03_2      Perl extension for AnyEvent interface to DBD::Pg async interface
p5-DBD-AnyData-0.110_1         DBI access to XML, CSV, and other formats
p5-DBD-CSV-0.54,1              DBI driver for CSV files
p5-DBD-Excel-0.06_1            Class for DBI drivers that acts on Excel files
p5-DBD-Google-0.51_2           Treat Google as a datasource for DBI
p5-DBD-InterBase-0.48_3        DBI driver for InterBase/Firebird/Yaffil RDBMS server
p5-DBD-LDAP-1.00               DBI interface for accessing LDAP servers
p5-DBD-Mock-1.45_1             Simple mock DBD implementation used for testing
p5-DBD-Multi-0.16_1            Manage Multiple Data Sources with Failover and Load Balancing
p5-DBD-ODBC-1.60               DBD module interfacing the ODBC databases
p5-DBD-Pg-3.7.4_1              Provides access to PostgreSQL databases through the DBI
p5-DBD-PgLite-0.11_2           PostgreSQL emulation mode for SQLite
p5-DBD-PgPP-0.08_1             Pure Perl PostgreSQL driver for the DBI
p5-DBD-SQLite-1.62             Provides access to SQLite3 databases through the DBI
p5-DBD-SQLite2-0.38            Provides access to SQLite2 databases through the DBI
p5-DBD-Sybase-1.16             Sybase DBI driver for Perl 5
p5-DBD-XBase-1.08              Provides access to XBase (dBase, Fox*) database files through DBI
p5-DBD-cego-1.4.0              Cego DBI driver for Perl 5
p5-DBD-mysql-4.050             MySQL driver for the Perl5 Database Interface (DBI)
p5-DBIx-AnyDBD-2.01_1          DBD independent class
rubygem-dbd-mysql-0.4.4_1      MySQL driver for DBI-for-Ruby
rubygem-dbd-pg-0.3.9_3         PostgreSQL driver for DBI-for-Ruby
rubygem-dbd-sqlite3-1.2.5_1    SQLite3 driver for DBI-for-Ruby

這裡會列出很多,你只需要安裝你需要的模組即可

安裝

# pkg install p5-DBD-mysql-4.050

 

這樣就可以了

 

使用CPANM

安裝 cpanm

# pkg search cpanm

p5-App-cpanminus-1.7042        Perl extension to get, unpack, build, and install modules from CPAN
p5-App-cpanminus-reporter-0.17 Perl extension to send cpanm output to CPAN Testers database

# pkg install p5-App-cpanminus-1.7042

 

安裝模組

# cpanm DBD::MariaDB

 

注意!用pkg有時會刪除一些衝突的套件

pkg雖然方便,但使用pkg安裝時有時會因為套件不相容,他會列出要刪除的套件,請不要都不看一直按Y,

然後刪了套件都不知道,因為我就幹過這種事,然後才發現套件被我自己刪了。

一開始我還懷疑被同事刪掉什麼的,原來是我自己白痴啊

例如

# pkg install p5-DBD-mysql
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (1 conflicting)
  - mysql56-client-5.6.44 conflicts with mariadb103-client-10.3.13_1 on /usr/local/bin/msql2mysql
Checking integrity... done (0 conflicting)
The following 4 package(s) will be affected (of 0 checked):

Installed packages to be REMOVED: <== 提示你會刪除套件
    mariadb103-client-10.3.13_1
    mariadb103-server-10.3.13
  <== 把你的server刪掉

New packages to be INSTALLED:
    p5-DBD-mysql: 4.050
    mysql56-client: 5.6.44 <== 但是只裝client不裝server

Number of packages to be removed: 2
Number of packages to be installed: 2

The operation will free 200 MiB.

Proceed with this action? [y/N]: n <== 上面要看清楚才按 y

 

相關文章

[PERL] 使用CPAN安裝模組@新精讚

參考資料

[1] https://perlmaven.com/install-perl-modules-on-freebsd

[2] https://mariadb.com/kb/en/library/perl-dbi/