Stuck with environmental variables - ruby

Ubuntu 14.04 LTS.
Rails 4.2.5
In Ubuntu terminal I did:
1. FOOD2FORK_KEY="359c93f1c292c674d95237ca05fe87cc"
2. export FOOD2FORK_KEY
Now I can check:
set | grep FOOD2FORK_KEY
And get
FOOD2FORK_KEY=359c93f1c292c674d95237ca05fe87cc
_=FOOD2FORK_KEY
If in the terminal I launch irb and write:
puts ENV["FOOD2FORK_KEY"]||"It is nill"
I get:
359c93f1c292c674d95237ca05fe87cc
=> nil
But if I try to run a test.rb in Eclipse, I get "It is nill".
In other words, my project needs this environmental variable to be set.
But somehow I can't cope with this problem.
Could you help me understand what and why this environmental var acts like that? And how can I make it visible in my project?
Thank you in advande.

You have two options:
Add your environment variables to /etc/environment so they become persistent and system-wide available (more info here: https://help.ubuntu.com/community/EnvironmentVariables)
Add those environment variables in Eclipse project configuration (I don't use Eclipse, but it should be located in Run -> Run Configurations... and Select tab "Environment"

Just to add an explanation of why you're seeing this behaviour:
When you export a variable it becomes visible to any child processes. As you've launched irb from the shell in the terminal irb is a child of the shell so the value is visible. However, if you launch Eclipse separately e.g. from a different terminal or from the GUI then the value will not be visible from there.
hugomarisco's suggestions are 2 good approaches to solving this.

Related

How to enable NetBeans 15 for Mac honour the system environment variables with Gradle builds

I have recently started to use GitHub Packages to distribute our shared libraries internally and have retrospectively changed the Gradle build configuration to use credentials based on system environment variables, rather than hard-coded e.g.
repositories {
mavenLocal() // only use when testing -SNAPSHOT locally
mavenCentral() // third-parties
maven { // our-library
name = "MyLibrary"
url = "https://maven.pkg.github.com/MyCompany/mylibrary"
credentials {
username = project.findProperty("git_username") ?: System.getenv("git_username")
password = project.findProperty("git_token") ?: System.getenv("git_token")
}
}
}
Unfortunately no matter how many environment variables I changed, whether in ~/.zshrc or .zshenv or .bash_profile or /etc/launchd.conf the build was indicating that the credentials were prohibited, or more accurately were resolved as nul.
Each time I changed a config I also ran the appropriate source to ensure it was active, I even resorted to rebooting, just in case.
The environment variable would always show in the terminal confirming the environment variable was always set up correctly, e.g. echo $git_username or printenv yielded the environment variable and expected sensitive token.
After a lot of experimenting and with the help of a colleague we determined that launching NetBeans 15 from the dock wasn't helping, so instead we also added the following line to ~/.zshrc
alias netbeans="/Applications/NetBeans/Apache\ NetBeans\ 15.app/Contents/MacOS/netbeans &"
But now to launch NetBeans I can't use the dock icon, but manually launch the terminal and then type
netbeans
Here's the new lines added to ~/.zshrc
#
# RW - For GitHub Package access
#
export git_username=NotApplicableUsesToken
export git_token=redacted1
export git_publish_username=NotApplicableUsesToken
export git_publish_token=redacted2
#
# RW - So Netbeans launches and honours the environment variables above
#
alias netbeans="/Applications/NetBeans/Apache\ NetBeans\ 15.app/Contents/MacOS/netbeans &"
My question is, why didn't NetBeans when launched from the dock discover the environment variables? How should I configure NetBeans to pickup the environment variables without this workaround?
The Aqua GUI doesn't read any of the shell configuration files, e.g. .bash_profile, .bashrc, .login, .profile, .zprofile, or .zshrc. You were correct to start looking at launchd. Unfortunately /etc/launchd.conf is no longer supported and the file is not read.
Apple's Runtime Configuration Guidelines in the Environment Variables section states:
There are two ways to make environment variables available to an application. The first is to define the variables in a Terminal session and then launch the application from the same session. ...
The second way to associate environment variables with an application is to include the LSEnvironment key in the application’s information property list file. ...
Editing an application's plist doesn't seem like the best idea and your changes may be lost when the application is updated.
There is a third approach.
launchctl has setenv, unsetenv, and getenv sub-commands for managing environment variables. However the environment variables are not persisted across launchd instances.
It seems that a common approach is to create an agent job .plist in ~/Library/LaunchAgents that runs at user login to macOS that will execute launchctl setenv to set the environment variables that should be available to applications launched from the dock. There are discussions at "Set systemwide variable with /etc/launchd.conf does not work in 10.10" and "Environment variables for GUI apps" that point to resources for this approach. You may also want to see Creating Launch Daemons and Agents.
I haven't tested or tried this approach myself.

How to temporarily disable the "java" command in cmd

I have a situation where I need to test a program with and without Java "installed". Instead of uninstalling and reinstalling for each test, I figured it would be ideal if I could simply disable the "java" command from working in cmd as this is the way the program determines if Java is installed. Is there an easy way to do this? I have tried removing any mentions of Java from the Environment variables (I'm on Windows 10 Education), but this does not seem to have had any effect. I am okay with hacky solutions as I just need this for my own quick tests on my machine.
Check the location of the java executabe with
c:\> where java
This may return multiple instances of java.exe in different directories of your PATH. Remove all returned directories from the PATH and restart your cmd.exe, because cmd will pick up changes in the environment variables only after it is restarted.
Remove all the paths of java from the environment variables(from user variables and System variables) then start cmd and type java, it should be unrecognised.

Setting environment variables at Qt Creator by sourcing a shell script

I am trying to configure the "Run Settings" on Qt Creator 3.0.1.
I would like to set the value of many environment variables by sourcing a shell script 'myScript'.
However, Deployment's Custom Process Step apparently doesn't accept 'source' as a command.
If I execute the script instead of sourcing it, it sets the environment variables of the shell process in which it is executed, which is not the same where Qt Creator runs the executable.
Is it possible to use 'myScript' to configure the environment variables ? How should I call it?
Ofcorse, You can run qt via scrypt. This is very simply. My script is below. Ofcorse you need environment variables in concret file. In my case this file is environment-setup
#!/bin/bash
echo "ustawienie zmiennej /usr/local/angstrom/arm/environment-setup"
# set concret variables important is . /
. /usr/local/angstrom/arm/environment-setup
echo "Uruchomienie qtCreator"
# lunched qtcreator
$HOME/Qt/Tools/QtCreator/bin/qtcreator
You also can set this script as linked to main icon qt in your start menu. After this, all you need to run qt is only click in your shortcut in menu
I think currently there's no proper way to set QtCreator build environment variables using a script. For example in this guide by ICS three options are mentioned in the "Set Up the Environment" section:
1. You can always start Qt Creator in the same shell/console session where you previously ran the environment setup script (i.e. /opt/poky/2.2.1/environment-setup-armv5e-poky-linux-gnueabi). This option is the easiest, but means that you can’t simply launch Qt Creator from a desktop shortcut or similar method. It might also cause problems if you want to build for the desktop or another embedded platform within the same session.
2. You can add the environment variables to the kit’s settings. This option is a little more work to set up, but avoids the issues of the shell setup.
3. A third option is to add the environment variables to your project settings, but that means adding it to every project that uses the kit.

Maven 3.0.5 installed in Windows 7 but not able to run through command prompt

As per suggestions given in this site i have added the required variables and values as below too but no response
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25
M2=%M2_HOME%\bin
M2_HOME=C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin
PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%M2_Home%\bin
Please help me
Your path configuration has a M2_Home instead of M2_HOME. It should be all uppercase
%M2_HOME%
Also notice, you are specifying bin twice, should
M2_HOME=C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5
I had same situation multiple times, i.e. configured M2_HOME as user env variable and added it to PATH (system env variable), i.e.
PATH=%M2_HOME%\bin; ...
However sometimes (randomly) Windows don't resolve variable in path, run "echo %PATH%" in your console. In my case I can still see %M2_HOME% there instead of resolved path to maven installation directory. It seems to be a bug in Windows itself, which is present in WinXP and Win7 at least.
I have resolved it as follows:
Open env variables, change M2_HOME (user one) to correct value. Press OK to save and close window
Open env variables again, now open PATH (system one) variable details, make sure M2_HOME is there and press OK, i.e. just save without any modification.
Now, open command line and check "echo %PATH%" - there should be resolved path. Confirm by running "mvn --version".
I know it really sounds like a black magic, but it should work...

Axis 2 can't see JAVA_HOME on my Mac (soapUI and wsdl2java)

Question : Why can Axis 2 not see where Java home is? Have I set it incorrectly?
Summary : I'm attempting to use Axis 2 with soapUI to generate Java objects from a wsdl on my Mac. However, I get the error "You must set the JAVA_HOME variable before running Axis2 Script."
If I type echo $JAVA_HOME into the command line, it says
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
I've navigated to the JavaVirtualMachines folder and the jdk is indeed there.
I also have edited ~/.bash_profile to say
export JAVA_HOME=$(/usr/libexec/java_home)
Another solution would be to start SOAP UI from the terminal as your .profile will be already loaded.
open -a /Applications/SoapUI-x.x.x.app/
Are you launching SoapUI by clicking on an icon? In that case, SoapUI wouldn't necessarily have access to environment variables set in your bash startup scripts.
Take a look at this question and this one about setting environment variables so that they're accessible to GUI apps. Basically, you may have to modify some system-wide configuration files.

Resources