Cannot run Swift under Ubuntu after closing the terminal - linux

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.

Related

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

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.

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

How to customize which Windows $PATH environment variables are imported into Cygwin?

I would like to customize the $PATH variables included in the Cygwin environment, how can I do this? One solution I know of is to add the following line to the end of the Cygwin.bat file:
PATH="/usr/local/bin:/usr/bin:/bin"
By default the shortcut starts bin/mintty.exe, how can I change that default behavior?
All Windows environment variables are included in your Cygwin environment automatically on startup. If you'd like to customize what they are, you can overwrite the whole $PATH variable using a line similar to what you already mentioned in your Cygwin.bat file:
PATH="colon:separated:list:of:all:paths"
Also if you'd like to change which terminal is used by Cygwin, one alternative is rxvt.
Another popular solution seems to be using PuttyCyg to putty directly into your Cygwin installation to get the benefits of the Putty terminal. See the effective-cygwin
GitHub page for setup instructions and more.
See this stackoverflow post for a full list of suggested alternatives to the default Cygwin terminal.

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.

How do I pass an environment variable to a Netbeans Makefile on Ubuntu?

I'm using Netbeans on Linux (Ubuntu 9.04) to build a C project.
How do I pass in an environment variable so that's it's visible to the Makefile?
If I do a normal export MYVAR="xyz" and then run make from the command line this works fine of course.
But Netbeans doesn't seems to use the .bashrc environment, so if I click "build" in Netbeans, the make fails.
Interestingly, the problem doesn't seem to occur on MacOSX - I've added the variable to ~/.MacOSX/environment.plist, and that value is visible to Netbeans.
I found this post which suggested modifying ~/netbeans-6.8/etc/netbeans.conf. I've tried this, by adding -J-DMYVAR=xyz to the end of netbeans_default_options, ie:
netbeans_default_options="-J-client -J-Xverify:none -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true -J-DMYVAR=xyz"
But this didn't seem to work.
Edit:
This answer is possibly not valid for Unity-based flavours of Ubuntu.
The issue is actually nothing to do with NetBeans - it's related to the Ubuntu (ie Gnome) Launcher.
As this blog post explains, you need to add variables to the rather obscure ~/.gnomerc (No Mercy? :) file in order for them to be passed to applications started with Launcher!
So just edit ~/.gnomerc and add the variables as you would to ~/.bashrc, eg:
export MYVAR="xyz"
and logout/login.

Resources