In RubyMine the PATH when running rake tasks, for example, never contains /usr/local/bin, which I need because git is in there.
Is there a rubyMine-wide config of PATH, so I don't have to modify each target?
Set your environment variables in ~/.MacOSX/environment.plist or use the Environment Variables Preference Pane and they will apply to all of your applications. See Tip: How to setup Environment variables for RubyMine on Mac OS X
for more information.
RubyMine does not currently have an app-wide PATH setting.
In Mountain Lion there is no longer any reliable way to set the environment like there was using Environment Variables Preference Pane or ~/.MacOSX/environment.plist.
The easiest way to get the same environment in RubyMine as you have in the terminal is to launch RubyMine from Terminal with this:
open -a /Applications/RubyMine.app/
Related
i need to set an environment variable for the rails app to use
SECRET_KEY_BASE=9941144eb255ff0ffecasdlkjqweqwelkjasdlkjasd
the config settings for production is as shown below
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
how can i set the environment variable using the linux command
export VARNAME="my value"
I tried to set the variable but looks like it needs to be for the right user. Sorry i am not an expert in linux.
I appreciate any help! Thanks!
export VARNAME="my value"
Well the above works for your current terminal session. After this command, all the subsequent commands can access this variable. Try running this:
echo $VARNAME
It will print the value my value in the console. If you want this behaviour to be persisted, you need to place the export command in your OS' config file (~/.bashrc in case of Ubuntu).
After editing this file, either restart your terminal, or run this:
source ~/.bashrc
This will reload the file in your current terminal session. Alternatively, you can try running your Rails server (or a rake command) as follows:
VARNAME="my value" rails s
For your local development I suggest you to use dotenv (https://github.com/bkeepers/dotenv) or figaro (https://github.com/laserlemon/figaro) and follow the README you find in the gem itself. This gives you much more flexibility than using directly environment variables because you set them only for this specific project and each project can have different of them.
You need to have either a .env file or a application.yml file where you will define your environment variables.
Remember to not commit or push this file to your repository because it contains sensible information!
When you will deploy to production you can use real environment variables or use admin panel control (on Heroku for example)
Just a quick question to which I couldn't find an answer on stackoverflow.
If it is easy to have environment variable for staging and production (on heroku for example), how can I set environment variable for my localhost (development environment)? (I am on a mac)
As of today I hardcode my api credential for development environment and I don't feel comfortable with that.
Thanks !
Use dotenv is intended to be used in development:
Add your application configuration to your .env file in the root of your project.
S3_BUCKET=YOURS3BUCKET
SECRET_KEY=YOURSECRETKEYGOESHERE
You may also add export in front of each line so you can source the file in bash.
in .bashrc
export S3_BUCKET=YOURS3BUCKET
export SECRET_KEY=YOURSECRETKEYGOESHERE
Then access in rails app ENV['S3_BUCKET']
Environment variables are best placed in your .bash_profile file which lives in your home directory on the Mac: /Users/you/.bash_profile. Open that file and add something like this to the end of it:
export MY_ENV_VAR=my_env_value
or
export MY_ENV_VAR="a string with spaces in it"
export is a shell command that sets environment variables. Your .bash_profile is a bash script that runs every time you open a new shell session (open a terminal window) and therefore your export commands will run and set the env vars.
Then they will be available in the ENV constant when you're in Ruby.
Edit /Users/your_user_name/.bash_profile and add there:
export RAILS_ENV=development
Never had such problem before with vps that I set up from zero, this one (Ubuntu 12.04, 64bit) was installed by some other developer.
The problem
in .bashrc file i have:
export FACEBOOK_ID=123456789
export FACEBOOK_SECRET=987654321
now in terminal if I type env I see these variables.
if I open rails console and type ENV["FACEBOOK_ID"] or ENV["FACEBOOK_SECRET"] I also can see the apropriate values.
The problem is that I have to use FACEBOOK_ID in the app in a view file and I do it with:
<%= ENV["FACEBOOK_ID"] %>
on local machine this returns the right value, in production on vps it returns nothing.
My idea is that the vps was not set up correctly, I couldnt find apache on it or ngnix, and the app is in var/www/apps/app_name/.
What could be wrong and how can I get this env variables in my template?
update
files available in root directory:
.bash_profile .bashrc .cshrc .zprofile .zshrc
Don't put it in local environment. What to do when you deploy the app? What to do when you want to develop another app on your local machine which use Facebook id as well?
Use Figaro gem. It's built for handling such case, env variables and private data. The env variables can be set in YAML file in app and won't be committed to repo. You won't regret.
On Linux and OS X, I'm accustomed to running Rake tasks in specified Rails "environments" by doing this:
$ export RAILS_ENV=monster_island ; rake monsters:destroy_all
How can I do the equivalent if I'm running the task on Windows XP in a Windows console?
c:>set RAILS_ENV=monster_island
If you run set without any other arguments, you will see the environment variables that are set. Running set in a console will set that variable for just that console and won't be persisted across sessions or to other consoles.
You can also set it permanently in the Control Panel - open System, select Advanced, and then Environment Variables (this may vary slightly depending on your version of Windows).
Of course you can use 'setX' (instead of simply 'set' if you want the variable to persist between console sessions (and you don't want to navigate through the various screens/tabs in the Control Panel
I've set up Passenger in development (Mac OS X) and it works flawlessly. The only problem came later: now I have a custom GEM_HOME path and ImageMagick binaries installed in "/usr/local". I can put them in one of the shell rc files that get sourced and this solves the environment variables for processes spawned from the console; but what about Passenger? The same application cannot find my gems when run this way.
I know of two solutions. The first (documented here) is essentially the same as manveru's—set the ENV variable directly in your code.
The second is to create a wrapper around the Ruby interpreter that Passenger uses, and is documented here (look for passenger_with_ruby). The gist is that you create (and point PassengerRuby in your Apache config to) /usr/bin/ruby_with_env, an executable file consisting of:
#!/bin/bash
export ENV_VAR=value
/usr/bin/ruby $*
Both work; the former approach is a little less hackish, I think.
Before you do any requires (especially before requiring rubygems) you can do:
ENV['GEM_HOME'] = '/foo'
This will change the environment variable inside this process.
I found out that if you have root priviledges on computer then you can set necessary environment variables in "envvars" file and apachectl will execute this file before starting Apache.
envvars typically is located in the same directory where apachectl is located - on Mac OS X it is located in /usr/sbin. If you cannot find it then look in the source of apachectl script.
After changing envvars file restart Apache with "apachectl -k restart".
I've run into this issue as well. It appears that Passenger doesn't passthrough values set using the SetEnv apache directive - which is unfortunate.
Perhaps it might be possible to set environment variables in your environment.rb or boot.rb (assuming you're talking about a Rails app; I'm not familiar with Rack but presumably it has similar functionality)