简体   繁体   中英

Ruby: Can I update the system environment variables?

Is there a way to update a system's PATH variable through Ruby, permanently? I have the following:

envPath = ENV["PATH"].dup
if envPath.include? "C:\\oracle\\product\\11.2.0\\client_1\\bin;" then
    envPath.slice! "C:\\oracle\\product\\11.2.0\\client_1\\bin;"
    ENV["PATH"] = envPath
    puts ENV["PATH"]
end

This successfully removes the variable I want to, but only for the current window - not permanently.

It's more a question about general computing and process behaviour not ruby special.

No this is not possible during runtime . Only a father process can configure the environment of it's child before start. Changing the environment of the father process or other processes during runtime isn't supported by any OS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM