macOS 11.6.1下安装Rugged时LIBSSH2依赖缺失导致SSH传输支持无法启用的技术求助
Your core issue here is that libssh2 (which Rugged relies on for SSH support) can't locate the libssl library from your installed OpenSSL 3.0.0, leading to SSH transport being disabled during the build. Let's walk through the steps to resolve this:
1. Ensure libssh2 is built against your OpenSSL 3 installation
First, we need to make sure libssh2 is compiled to use your openssl@3 instead of the system's default OpenSSL (which might be outdated or incompatible):
- Uninstall any existing
libssh2that might be linked to the wrong OpenSSL:brew uninstall --ignore-dependencies libssh2 - Reinstall
libssh2, explicitly pointing it to your OpenSSL 3 path:
This ensuresPKG_CONFIG_PATH=/usr/local/opt/openssl@3/lib/pkgconfig brew install libssh2libssh2uses your OpenSSL 3 libraries instead of the system version.
2. Reinstall Rugged with explicit CMake flags
Now, we'll reinstall Rugged and tell CMake exactly where to find libssh2 and OpenSSL 3:
- First, remove the existing Rugged installation:
gem uninstall rugged - Install Rugged 1.2.0 with the necessary build flags:
gem install rugged -v 1.2.0 -- \ --with-cmake-configure-options="-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@3 -DLIBSSH2_INCLUDE_DIR=/usr/local/opt/libssh2/include -DLIBSSH2_LIBRARY=/usr/local/opt/libssh2/lib/libssh2.dylib"
3. Verify the build includes SSH support
After installation, check the build output again—you should no longer see SSH, SSH transport support under the "Disabled features" section. If you want to double-check, you can run:
gem environment gemdir
Navigate to the Rugged gem directory and inspect the build logs or run a quick test script to confirm SSH functionality works.
4. If using Bundler
If you're using Bundler to manage dependencies, add this to your Gemfile:
gem 'rugged', '~> 1.2.0'
Then set the build config for Rugged before running bundle install:
bundle config build.rugged --with-cmake-configure-options="-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@3 -DLIBSSH2_INCLUDE_DIR=/usr/local/opt/libssh2/include -DLIBSSH2_LIBRARY=/usr/local/opt/libssh2/lib/libssh2.dylib" bundle install
Quick Troubleshooting Tip
Ensure your environment variables are active by running:
echo $PKG_CONFIG_PATH
It should include both /usr/local/opt/openssl@3/lib/pkgconfig and /usr/local/opt/libssh2/lib/pkgconfig. If not, add the libssh2 path to your .zshrc:
echo 'export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/libssh2/lib/pkgconfig"' >> ~/.zshrc source ~/.zshrc
内容的提问来源于stack exchange,提问作者kenshin23

