gem install 不会重建 gem 的所有实例

gem install 不会重建 gem 的所有实例
user@sv1 [/home/user/]# env|grep GEM
GEM_HOME=/home/user/.gems/2.1
GEM_PATH=/home/user/.gems/2.1

user@sv1 [/home/user/]# gem install mysql2
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.18
1 gem installed

that installs mysql2.so in multiple locations:
user@sv1 [/home/user/]# find /home/user/.gems -name mysql2.so
/home/user/.gems/2.1/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.18/mysql2/mysql2.so
/home/user/.gems/2.1/gems/mysql2-0.3.18/ext/mysql2/mysql2.so
/home/user/.gems/2.1/gems/mysql2-0.3.18/lib/mysql2/mysql2.so

user@sv1 [/home/user/]# ls -l /home/user/.gems/2.1/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.18/mysql2/mysql2.so
-rwxr-xr-x 1 user user 64842 mar 18 16:13 /home/user/.gems/2.1/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.18/mysql2/mysql2.so
user@sv1 [/home/user/]# ls -l /home/user/.gems/2.1/gems/mysql2-0.3.18/ext/mysql2/mysql2.so
-rwxr-xr-x 1 user user 64842 mar 18 16:13 /home/user/.gems/2.1/gems/mysql2-0.3.18/ext/mysql2/mysql2.so

now I want to rebuild this extension so I do:
user@sv1 [/home/user/]# gem install mysql2
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.18
1 gem installed

user@sv1 [/home/user/]# ls -l /home/user/.gems/2.1/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.18/mysql2/mysql2.so
-rwxr-xr-x 1 user user 64842 mar 18 16:13 /home/user/.gems/2.1/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.18/mysql2/mysql2.so
user@sv1 [/home/user/]# ls -l /home/user/.gems/2.1/gems/mysql2-0.3.18/ext/mysql2/mysql2.so
-rwxr-xr-x 1 user user 87485 mar 18 16:16 /home/user/.gems/2.1/gems/mysql2-0.3.18/ext/mysql2/mysql2.so

如您所见,/home/user/.gems/2.1/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.18/mysql2/mysql2.so 未重建。更糟糕的是,该文件实际上在 ruby​​ 代码中“需要‘mysql2’”时使用。这会阻止重建/更新 gem。当然,我可以通过删除这个旧文件然后“gem install”来解决这个问题,但这会导致记住很多新变量,并且很难诊断很多问题。如何使用 gem 命令重建 gem 的所有文件(此处为 mysql2.so)?或者也许是“gem”程序中的错误?

该问题并不特定于 mysql2 gem,因为其他 gem 的行为方式也相同。

有人可能会说,当 gem 的版本没有改变时,没有必要重建它 - 但是当它链接到的库被更新/改变时就需要重建它了(例如 mysql2 gem 的 libmysqlclient)

答案1

您可能正在寻找以下pristine选项:

gem pristine mysql -v 0.3.18

或者没有-v我相信它只会在最新版本上运行但也有--all选项。

gem help pristine参阅文档:

Restores installed gems to pristine condition from files located in the gem
cache

使用pristine还包括重建任何 gem 扩展,将二进制文件与当前库重新链接。

相关内容