无主目录且无sudo权限的Jenkins用户如何安装RVM?
Got it, let's work through this step by step—you're dealing with a Jenkins user that has no defined $HOME, no sudo access, and hit two roadblocks with RVM: first, permission denied trying to install to /.rvm, then a space-in-path error when you pointed $HOME to your workspace. Here's a fully sudo-free solution that plays nicely with Jenkins:
Step 1: Create a space-free installation directory in your workspace
Since RVM still struggles with paths containing spaces, make a dedicated subfolder in your Jenkins workspace that has no spaces (you already have write access here):
mkdir -p "$WORKSPACE/rvm_local"
Step 2: Install RVM directly to this custom path
Instead of relying on $HOME or needing sudo, tell RVM exactly where to install using the --path flag. Run this command:
curl -sSL https://get.rvm.io | bash -s stable --path "$WORKSPACE/rvm_local"
This skips all the default home directory checks and installs everything straight into your workspace's rvm_local folder—no root permissions needed.
Step 3: Load RVM into your current shell session
After installation, you need to source RVM's script to make its commands available:
source "$WORKSPACE/rvm_local/scripts/rvm"
Verify it worked by checking the RVM version:
rvm --version
Step 4: Set up for future Jenkins runs
If you need to use RVM in subsequent steps of the same Jenkins job, add the source command at the start of your shell script. For repeat jobs, you can also define the rvm_path environment variable in your Jenkins job configuration (under "Environment Variables") as:rvm_path=$WORKSPACE/rvm_local
This ensures RVM always knows where to look without extra setup.
Step 5: Install Ruby (optional)
Now you can install any Ruby version you need—no sudo required:
rvm install 3.2.2 # Replace with your desired Ruby version
Ruby will be installed directly into $WORKSPACE/rvm_local/rubies, which you have full access to.
Why this works:
- We avoid the root-owned
/.rvmdirectory entirely by using your Jenkins workspace (which you control). - We skip the space-in-path issue by using a dedicated, space-free subfolder.
- All operations stay within your user's permissions—no sudo needed at any point.
内容的提问来源于stack exchange,提问作者grayaii

