How can I save an ENV VAR on Linux Ubuntu 16.04? - linux

I typed on my terminal the following command :
export BACKEND_URL="<confidential>"
. Apparently it was working, but when I turned off my computer and turned on again, I realized that this env var named BACKEND_URL It was not saved anymore. Why this happened ?

First of all:
This question would better fit the Unix&Linux StackExchange site than this web site.
However:
By typing "BACKEND_URL="<confidential>"" you set a variable which is valid for the currently running shell (terminal window) only.
If you close the terminal window, the variable is gone. The variable is also not valid for programs started from that terminal window.
If you add export (as you did), the variable is also valid for programs started from that terminal window.
However, still it is not valid for other terminal windows and if you close the teminal window, it will be gone.
When using one of the standard shells, you can add variables to the .profile file in your home directory.
When you are using bash, you can also add variables to the .bashrc file in your home directory.

Related

Cannot run Swift under Ubuntu after closing the terminal

I am trying to run the Swift compiler under Ubuntu. I followed this tutorial: https://itsfoss.com/use-swift-linux/ and everything seemed to work fine. I was able to run swift under Ubuntu.
However, when I closed the terminal, I was not able to run Swift anymore. The program was not found until I installed it again. I could not find any answers to this question as there aren't many people running Swift under Ubuntu.
It's not uninstalled, you just don't have the environment variables set up anymore, so Bash can't find the path to Swift. You can change that by exporting the appropriate environment variables in your .bashrc file.
When you followed the tutorial, you ran the following command:
export PATH=path_to_swift_usr_bin:$PATH
This command adds the path to the swift binary to your PATH environment variable. The PATH variable holds a list of places where Ubuntu will look for programs to run from the command-line. So if the Swift executable is not in one of the places listed in the PATH, your terminal will never find it.
There is a file in your home folder (the folder ~, which is an abbreviation for /home/username, where username is your username) named .bashrc, which runs whenever you open a new terminal window. If you need an environment variable to be available whenever you open the terminal, you should add the export line for that variable to your .bashrc.
In this case, your .basrhc should contain the same line above.
The important thing to remember is that your environment variables are not preserved between command-line sessions, so if you want to have an environment variable available every time you use the command-line, it needs to be defined in your .bashrc.

Why is Appcellerator Titanium's terminal different from my OSs terminal?

I'm having the following problem installing Titanium Studio. On my Mac (OSX Yosemite), the terminal shows that I have Node, NPM, Titanium, Alloy etc. all installed and 'callable' from any path. Titanium Studio keeps failing to run because it can't find the CLI.
If I go to Titanium's terminal view, absolutely nothing seems to be installed. Even 'ls', 'cd' etc. cannot be run. Anyone know what I'm missing here? It's like .bashrec never gets loaded or something. Would appreciate any pointers in the right direction,
cheers,
Wittner
Ok. Looks like this had nothing much to do with Titanium and everything to do with my system setup, but this might help others who experience the same symptoms.
Turns out that my .bash_profile was incorrectly set up.
.bash_profile is a batch file which holds information about (among other things) the current path. This file, if it exists, gets run every time terminal is started up. One of my path statements in the file ended without :$PATH
:$PATH concatenates the current path when you are putting a path command in the file e.g.:
export PATH=/etc/bin/
export PATH=/Applications:$PATH
The ':$PATH' at the end of the second statement ensures that the path now contains both /etc/bin/ and /Applications. Without :$PATH, the second line would have set the path to /Applications only, overwriting the /etc/bin/ entry.
So in effect all of the PATH commands before the last one had been overwritten. Terminal could not see where ls, cd or an of those command line tools were. My own terminal worked fine because I had it using ksh (Korn shell) which I had set up with some fancy colours and listing options. When Titanium tried to load a fresh copy of terminal, the PATH was effectively being overwritten and so Alloy, Node etc. where not visible to it.
I fixed up the erroneous PATH statements in the .bash_profile, restarted the app and now Titanium works fine.

customed command not found in a new terminal

everyone.
I had a basic question want to consult, about the environment variable setting.
After closed my one existed terminal which could execute compile(make) and do customed(mksdboot) command, i can't do mksdboot command anymore(I had execute a predefined setting environment variable shell script i.e. $ . ./arndale_envsetup.sh again) in the new terminal.
Cause i am a beginner in Linux, i am not very clearly about the environment variable setting rules.
i had tried to 'su' or 'sudo' to execute mksdboot, but no luck:(
ps. I had another project needs to compile in my PC(i didn't export PATH to .bashrc, only execute export PATH when i open a new terminal every time), may it efforts the original project's environment variable?
thanks.
[UPDATED]
i tried using $source ./arndale_envsetup.sh, relative commands worked finally.
but i still did't figure out the reason between work or not work. >"<
The command
history
will list what your previous commands where.
This might give you a pointer what set the path in the way you needed it.
You could also try to see where you command is via
locate mksdboot

define NDK_ROOT in cocos2DX mutiplatform game environment

I have just started working with cocos2dx android and I am following wonderful tutorial of http://www.raywenderlich.com/33750/cocos2d-x-tutorial-for-ios-and-android-getting-started . Now, I have successfully run my first hello world demo project by following this link. I also set environment parameters:
NDK_ROOT_LOCAL="/MY ANDROID NDK PATH/"
ANDROID_SDK_ROOT_LOCAL="/MY ANDROID SDK PATH/"
I followed tutorial perfectly as given in it, still I am facing problem while running my project second time, means I have to export DNK_ROOT every time from terminal to run my project & it's really tired and seemed not working for my further implementation.. and while I run project it says please define NDK_ROOT though I already define
second thing
I also manually define these variables in my .bash profile (create-android-project.sh) this way
NDK_ROOT_LOCAL = "/MY ANDROID NDK PATH/"
ANDROID_SDK_ROOT_LOCAL = "/MY ANDROID SDK PATH/"
What am I missing in setting up this?
To make those variables permanent (so every terminal shell you open hereafter has then) use your favorite text editor to update your bash profile (I chose vi to keep it in the terminal)
NOTE: the use of "~" in a path is just shorthand for your user directory. In your case it appears to be synonymous with saying "~" = "/Users/alex"
vi ~/.bash_profile
add the following lines and save (update these names and paths to match your actual environment, I am assuming everything is in the root of your user directory here):
export NDK_ROOT_LOCAL=~/android-ndk-r10b
export ANDROID_SDK_ROOT_LOCAL=~/sdk
Use source to run the profile in the current terminal session or just open a new terminal
source ~/.bash_profile
You can test to see if the variables are defined here (use whatever you named them)
echo $NDK_ROOT_LOCAL
echo $ANDROID_SDK_ROOT_LOCAL
[EDIT: noted that paths need to be tuned to your environment]
this way i can define my NDK ROOT
export NDK_ROOT=/Users/alex/android-ndk-r8b
If you are using MAC OSX please consider adding NDK_ROOT variable in Environments file. Linux directly read it when the instance of bash is initiated but in MAC you need to add it in a bit more detail. Try adding it.

Installing TexLive 2010 in Ubuntu 10.10: problem with PATH

I'm followint these instructions to install Kile+TexLive 2010 with package manager on my Ubuntu Maverick: http://ubuntuforums.org/showthread.php?t=141934
The problem I have is that when I finish downloading all the packages to my computer, I have to edit the path but Ubuntu doesn't recognize it. The lines are the following:
PATH=/usr/local/texlive/2005/bin/i386-linux:$PATH
export PATH
I run echo $PATH and as long as I don't close the terminal, the path appears with the echoing, but if I close it, the path disappears. Nevertheless (whether I close the terminal or not), I'm supposed to run texhash but I am told that the command is not found. I already tried editing the path by adding the two lines above to both .bashrc in my home directory and to bash.bashrc in /etc/ directory.
I'm just following the instructions linked above, but I'm a linux rookie. Could anyone help, please?
in order to permanently change any environment variable under Ubuntu/Linux, you must modify the files you mentioned (for example ~/.profile). If you simply issue an export via the terminal, its effect will end once the terminal is closed. Sometime it is needed to perform a logout/login for the changes to take effect.
Also, mind the syntax of what you write in the above mentioned file(s), like "'s around $PATH.
Refer to this question: https://serverfault.com/questions/44275/how-to-add-a-directory-to-my-path-in-ubuntu

Resources